Hello,
I have been working on a dragonball z game recently and I have encountered a problem with the sprites.I have traced the bitmap and everything else and even created a movieclip of the sprite.I have put this code on the movieclip-
- onClipEvent (load) {
-
step = 5;
-
}
-
onClipEvent (enterFrame) {
-
if (Key.isDown(Key.RIGHT) && this._x<550) {
-
this._x += step;
-
gotoAndPlay(2);
-
} else if (Key.isDown(Key.LEFT) && this._x>0) {
-
this._x -= step;
-
gotoAndPlay(10);
-
} else if (Key.isDown(Key.UP) && this._y>0) {
-
this._y -= step;
-
gotoAndPlay(15);
-
} else if (Key.isDown(Key.DOWN) && this._y<400) {
-
this._y += step;
-
gotoAndPlay(6);
-
}
-
}
I have put animations of the character walking on the differnet frames inside the movieclip.For eg-
I have shown the character walking right from frame 2-5,walking down from frame 6-9,walking left from frame10-14,walking up from frame 15-19.
THE PROBLEM is that whenever I press a specefic key(I will take the example of right) and keep it pressed,IT DOES NOT PLAY THE WHOlE ANI:MATION OF MOVING RIGHT.It just plays frame 2 and repeats it instead of playing frames 2-5 together.
HELP is required!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Your sprite's animation is not playing because when you press a key, remember you are in an onEnterFrame event, so every frame the gotoAndPlay function will try to go from the frame you specified, making every frame that frame, so it's never going to play the animation. That's logical, though sometimes difficult to see the error. you gotta do this:
"guy" is the instance name of my sprite
I wrote all the code in a main timeline frame, you could do it in an external as file and include it in the frame instead, if you have lot's of code.
You should try to write all the code separately, so you won't have parts of code lost in movieclips inside movieclips inside movieclips..... etc.
you can check this working example at
http://www.thenephilim.com.ar/guy.swf
and download it from
http://www.thenephilim.com.ar/guy.fla -
var step:Number = 8;
-
var flipped = -guy._xscale;
-
-
onEnterFrame = function() {
-
if (Key.isDown(Key.RIGHT)) {
-
guy._xscale = -flipped;
-
guy._x += step;
-
-
if(guy._currentframe < 6) {
-
guy.gotoAndPlay(6);
-
}
-
if(guy._currentframe < 14) {
-
guy.nextFrame();
-
} else {
-
guy.gotoAndPlay(6);
-
}
-
} else if (Key.isDown(Key.LEFT)) {
-
guy._xscale = flipped;
-
-
guy._x -= step;
-
if(guy._currentframe < 6) {
-
guy.gotoAndPlay(6);
-
}
-
if(guy._currentframe < 14) {
-
guy.nextFrame();
-
} else {
-
guy.gotoAndPlay(6);
-
}
-
} else {
-
guy.gotoAndStop(1);
-
}
-
}
-