-
[CS3, AS2] Simple movement with Acceleration
I'm working on making a platformer in Flash and so far have an okay script for making my character speed up to a maximum walking speed quickly, so the movement isn't jerky. The only problem I have is once the variable of the walking speed gets all the way up, it stays this way. If I press the left or right key again, the movement speed is still at 5 so it's jerky and I really want to find a way to have smooth acceleration when moving in my game. I'm trying to implement a way to check if the key is down, so I can set the speed back to 0 if a key is released, but I'm not really sure how. This is my code so far. I'm not sure if I need variables for my left and right speed, but I thought it might come in handy in the future.
Code:
onClipEvent (load)
{
rightSpeed=0;
leftSpeed=0;
}
onClipEvent (enterFrame)
{
if (Key.isDown(Key.RIGHT))
{
rightSpeed++;
if (rightSpeed > 5)
{
rightSpeed=5;
}
this._x+=rightSpeed;
}
if (Key.isDown(Key.LEFT))
{
leftSpeed++;
if (leftSpeed > 5)
{
leftSpeed=5;
}
this._x-=leftSpeed;
}
}
To rephrase my question, how could I do an event like Key.isUp? I know this doesn't exist, except with key listeners but I can't figure out how to use a listener. If someone could help me that would be great.
Thanks
Ethan
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
|