Actionscript Enterframe Movement
Posted
by
David
on Stack Overflow
See other posts from Stack Overflow
or by David
Published on 2011-02-25T23:22:04Z
Indexed on
2011/02/25
23:24 UTC
Read the original article
Hit count: 212
I am trying to make accelerated movement, but I am running into a problem that, for the life of me, I cannot understand.
My class definition:
public class Player extends MovieClip
{
private var stageRef:Stage;
private var key:KeyObject;
private var acceleration:int = .5;
private var curSpeed:int = 0;
public function Player(stageRef:Stage)
{
this.stageRef = stageRef;
addEventListener(Event.ENTER_FRAME, enterFrame);
key = new KeyObject(stageRef);
}
public function enterFrame(e:Event) : void
{
if(key.isDown(key.RIGHT)) {
x += 5;
}
}
}
This works to move my position in the x
direction at a constant rate.
However, if I change enterFrame to
public function enterFrame(e:Event) : void
{
if(key.isDown(key.RIGHT)) {
x += acceleration;
}
}
No movement occurs.
Is there something going on in the event I do not understand?
Why is it that I can have x
increased by a constant value but not a constant value as defined in a variable in the class?
Is it a scope issue?
© Stack Overflow or respective owner