O'Reilly logo

haXe 2 by Benjamin Dasnois

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action—Moving the character

In order to do so, we are going to await the ENTER_FRAME event that is triggered every time a new frame is drawn on the screen (frame drawing is automatically handled in Flash and you do not have to handle it through a loop like in other languages).

We will then move the character on each frame depending on its speed. Let's add the following to the Game class:

import flash.events.Event;
class Game
{
//previous code
public static function main(): Void
{
//previous code
//Add an event handler for every frame drawing flash.Lib.current.stage.addEventListener (flash.events.Event.ENTER_FRAME, enterFrame);
}
//previous code
private static function enterFrame(args : Dynamic)
{
player.x += horizontalSpeed;
}
}

What just ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required