Question

I am trying to make my character go down/up left/right

using this code (example)

if (Key.isDown(Key.LEFT, Key.DOWN))
{
    _x -= power;
    _root.char.gotoAndStop(6);
}

}

But when doing so this also registering the left key to frame 6 so it goes down left when I press left key..

Was it helpful?

Solution

You need a separate condition for each key, if you want each key to do something unique. Note that you'll need to modify the frame number specified in _root.char.gotoAndStop(6) for each respective key press.

if (Key.isDown(Key.LEFT))
{
    _x -= power;
    _root.char.gotoAndStop(6);
} else if (Key.isDown(Key.DOWN))
{
    _y += power;
    _root.char.gotoAndStop(6);
} else if (Key.isDown(Key.RIGHT))
{
    _x += power;
   _root.char.gotoAndStop(6);
} else if (Key.isDown(Key.UP))
{
    _y -= power;
   _root.char.gotoAndStop(6);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top