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—Updating the position

Now, let's update the positions at every frame. To do that, we will create a simple function and call it in our ENTER_FRAME event handler as follows:

private static function enterFrame(args : Dynamic)
{
player.x += horizontalSpeed;
updatePositions();
}
private static function updatePositions()
{
for(d in droppables)
{
d.y += 10;
if(d.y>= 450)
{
droppables.remove(d);
flash.Lib.current.stage.removeChild(d);
continue;
}
}
}

What just happened?

This is a pretty simple modification that just updates the position of every droppable and tests whether it is out of the stage or not. If it is, it then removes it from the list of droppables.

That's fine, but we still need the collision detection in order to know if our ...

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