public class World extends Sprite


private static const SCROLL_VELOCITY:Number = 130; 1

/* ... */

public function advanceTime(passedTime:Number):void


advanceGround(passedTime); 2



private function advanceGround(passedTime:Number):void


var distance:Number = SCROLL_VELOCITY * passedTime; 3


_ground.tileGrid.x -= distance; 4

_ground.tileGrid = _ground.tileGrid; 5

1 A constant defines the speed of movement: 130 points per second.

2 The new method advanceGround will do the work.

3 Since passedTime is given in seconds, a simple multiplication will yield the passed distance.

4 Move tileGrid.x to the left.

5 That’s a small API oddity: for the changes to show up, tileGrid has to be re-assigned.

There really isn’t much to it: all that we are doing is reducing the value of tileGrid.x a little in each

frame. The result is a neat, endless animation of the ground ribbon.

You’ll notice that the we are not moving the blue background in any way. That’s

intentional: by keeping it at a fixed position, we’re creating the illusion that it is

very far away.


Flappy Starling ought to be a game, but right now, the level of interactivity is rather … lacking. Thus,

the next step should be to make the bird’s flight follow some basic physical rules, and to let the

player take control.

We have two choices when it comes to physics:

• We could do it ourselves: Isaac Newton came up with a couple of formulas; we can plug those

into our code.

• Or we could add a physics library to our project and let it do the heavy lifting.

Which approach should we use?


More magazines by this user
Similar magazines