Sign in to follow this  
jamielightfoot

Flash actionscript help

Recommended Posts

(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

Share this post


Link to post
Share on other sites
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:
[code]
//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
}
[/code]

also, as a side note, event handlers are the way to go in flash. Edited by slicer4ever

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this