|
-
Help needed: Score in platform game AS2
kk, im having trouble getting my score system to work.
here is my code for my coins:
Code:
onClipEvent(enterFrame){
if(this.hitTest(_root.char)){
_root.score +=1;
this.swapDepths(666);
this.removeMovieClip();
}
}
and so the problem is that when i test my game it says: _level
and doesnt change even if i get a coin, another thing is that flash won't let me type in: root.score in my instances bar for the dynamic text box.
-
Just call the text box "score" as _root refers to where the box is so doesn't need to be included in the variable name.
Also, removeMovieClip() will not work with GUI created objects. It only works with dynamically loaded clips.
-
Senior Member
Another thing to note is that you will need to use score.text += 1, to change the text field's content.
On the long run though it would be a good idea to have a score variable and a scoreDisplay text field, and set scoreDisplay.text to the score variable, every time the score changes (or just every frame).
-
Orkaham52: im kind of a begginer so i need more simpler info.
-
and does anyone know how to make it so that my character doesnt keep falling through the ground if hes falling at a high rate. and i'd like it if you tell me exactly where i need to fix the code. and this is AS2.
Code:
onClipEvent (load) {
gravity = 0;
runspeed = 10;
jumpHeight = 10;
waterr = .7;
waterrspd = runspeed/1.5;
setrunspeed = runspeed;
scale = this._xscale;
hitTestVariable = -2;
this.gotoAndStop(2);
}
onClipEvent (enterFrame) {
gravity++;
this._y += gravity;
while (_root.ground.hitTest(this._x, this._y, true)) {
this._y--;
gravity = 0;
}
if (_root.water.hitTest(this._x, this._y, true)) {
if (gravity>0) {
gravity *= waterr;
}
runspeed = waterrspd;
} else {
runspeed = setrunspeed;
}
if (Key.isDown(Key.RIGHT)) {
this._x += runspeed;
this._xscale = scale;
if (_root.ground.hitTest(this._x, this._y+3, true)) {
this.gotoAndStop(1);
} else {
this.gotoAndStop(2);
}
} else if (Key.isDown(Key.LEFT)) {
this._x -= runspeed;
this._xscale = -scale;
if (_root.ground.hitTest(this._x, this._y+3, true)) {
this.gotoAndStop(1);
} else {
this.gotoAndStop(2);
}
} else {
if (_root.ground.hitTest(this._x, this._y+3, true) && !Key.isDown(79) && !Key.isDown(73)) {
this.gotoAndStop(3);
}
}
if (Key.isDown(79) && !Key.isDown(Key.SPACE) && !Key.isDown(65) && !Key.isDown(68) && !Key.isDown(73)) {
this.gotoAndStop(5);
}
if (Key.isDown(73) && !Key.isDown(Key.SPACE) && !Key.isDown(65) && !Key.isDown(68) && !Key.isDown(79)) {
this.gotoAndStop(4);
}
if (Key.isDown(Key.SPACE) && _root.ground.hitTest(this._x, this._y+3, true)) {
gravity = -jumpHeight;
this._y -= 4;
this.gotoAndStop(2);
}
if (_root.ground.hitTest(this._x+(_width/2)+hitTestVariable, this._y-(_height/2), true) || _root.ground.hitTest(this._x+(_width/2)+hitTestVariable, this._y-(_height/6), true) || _root.ground.hitTest(this._x+(_width/2)+hitTestVariable, this._y-_height, true)) {
this._x -= runspeed;
}
if (_root.ground.hitTest(this._x-(_width/2)-hitTestVariable*2, this._y-(_height/2), true) || _root.ground.hitTest(this._x-(_width/2)-hitTestVariable*2, this._y-(_height/6), true) || _root.ground.hitTest(this._x-(_width/2)-hitTestVariable*2, this._y-_height, true)) {
this._x += runspeed;
}
if (_root.ground.hitTest(this._x, this._y-_height, true)) {
gravity = 1;
}
if (_root.gravity_lift.hitTest(this._x, this._y, true)) {
gravity -= 2;
}
}
-
Senior Member
Which would you like more info on, the text fields, or the score variable?
As for the falling, your code is a bit old school. I'd suggest you put all the code on one frame, not on each movie clip. It makes it wayy easier to organise and debug.
Since your still learning though I'll give you a more immediate solution:
Code:
gravity++;
for (i=0; i<4; i++) {
if (!_root.ground.hitTest(this._x, this._y, true)) {
this._y += gravity/4;
}
}
This code replaces the old "gravity++;" and "this._y += gravity;" lines. What it does, is it checks for a collision with the ground every quarter of it's movement. It should fix your problem, but if it doesn't you can change both 4s to 5s or 6s.
It's very inefficient and slow, though, and you'll find that most flash platform games are made with tile-based engines these days, as they are faster, more reliable and easier to modify and make levels for. If you're interested in learning how to make a tile-based game, and I humbly suggest you do, try googling around.
-
Thanks soooo much ur very helpful
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|