You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
public class World extends Sprite<br />
{<br />
private static const SCROLL_VELOCITY:Number = 130; 1<br />
/* ... */<br />
public function advanceTime(passedTime:Number):void<br />
{<br />
advanceGround(passedTime); 2<br />
_bird.advanceTime(passedTime);<br />
}<br />
private function advanceGround(passedTime:Number):void<br />
{<br />
var distance:Number = SCROLL_VELOCITY * passedTime; 3<br />
}<br />
_ground.tileGrid.x -= distance; 4<br />
_ground.tileGrid = _ground.tileGrid; 5<br />
1 A constant defines the speed of movement: 130 points per second.<br />
2 The new method advanceGround will do the work.<br />
3 Since passedTime is given in seconds, a simple multiplication will yield the passed distance.<br />
4 Move tileGrid.x to the left.<br />
5 That’s a small API oddity: for the changes to show up, tileGrid has to be re-assigned.<br />
There really isn’t much to it: all that we are doing is reducing the value of tileGrid.x a little in each<br />
frame. The result is a neat, endless animation of the ground ribbon.<br />
<br />
You’ll notice that the we are not moving the blue background in any way. That’s<br />
intentional: by keeping it at a fixed position, we’re creating the illusion that it is<br />
very far away.<br />
Physics<br />
Flappy Starling ought to be a game, but right now, the level of interactivity is rather … lacking. Thus,<br />
the next step should be to make the bird’s flight follow some basic physical rules, and to let the<br />
player take control.<br />
We have two choices when it comes to physics:<br />
• We could do it ourselves: Isaac Newton came up with a couple of formulas; we can plug those<br />
into our code.<br />
• Or we could add a physics library to our project and let it do the heavy lifting.<br />
Which approach should we use?<br />
18