Book Image

haXe 2 Beginner's Guide

5 (1)
Book Image

haXe 2 Beginner's Guide

5 (1)

Overview of this book

Table of Contents (21 chapters)
haxe 2
Credits
Foreword
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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 player touches a tomato or a bomb.