Flash actionscript help

Started by
1 comment, last by jamielightfoot 11 years, 9 months ago
(beginer) I am making a platforming game in flash and I am stuck on an action script command. Currently I have it set to have the running (single frame) movment play when the right/left key is pressed. What I am trying to do is to have it play a running animation (legs moving) while the key is pressed down. So I extended the frames of the character on the "run" sequence and added the running frames. Now when the character runs it shows the first frame, and then as soon as the character stops moving it plays the running animation. I want to just have it play from the time the key is pressed down, not just from when it comes back up. This is the code I have now
if (Key.isDown(Key.LEFT)) {

if (speed>-maxmove) {

speed--;

}
this.gotoAndPlay("run");

this._xscale = -100;
My guess would be I need to change the "Key.isDown" to something else but I dont know, thanks a lot and sorry for not knowing anything
Advertisement
you need to keep track of the release/press states, essentially what you are saying now is: "while left key is down, go to the first frame of "run", then play it", and it will keep going to that first frame until you release the key.

so what you need to do is keep a variable of when you change states, like so:

//In setup code:
var LeftDown=false;

//in main loop:
if(Key.isDown(Key.LEFT)){
if (speed>-maxmove) {
speed--;
}
if(LeftDown==false){
this.gotoAndPlay("run");
}
LeftDown=True;
}else{
LeftDown=false;
//Optional gotoAndStop here
}


also, as a side note, event handlers are the way to go in flash.
Check out https://www.facebook.com/LiquidGames for some great games made by me on the Playstation Mobile market.
alright, i got it working for the most part, or enough to figure it out, thank you so much

This topic is closed to new replies.

Advertisement