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 – Adding balls


Now, let's add some falling "balls".

In order to do this, we will create a static list of droppables that we will keep updated (adding newly created ones and removing those that are not used anymore).

We will also use a haxe.Timer to regularly create a new droppable. Reference to this timer will be held in a static variable.

We will update droppables' position on each frame.

So, let's create our timer in our main function and use an anonymous function to create our new droppable:

   public static function main(): Void
   {
      player = new Guy();
      //Add it to the stage
      flash.Lib.current.stage.addChild(player);

      //Place it at the good place on stage.
      player.x = 200;
      player.y = 300;
      player.width=50;
      player.height = 100;
      
      flash.Lib.current.stage.addEventListener(flash.events.KeyboardEvent.KEY_DOWN, keyDown);
      flash.Lib.current.stage.addEventListener(flash.events.KeyboardEvent.KEY_UP, keyUp);
      flash.Lib...