Starling handbook Preview
Starling handbook Preview - Gamua, Starling Framework, Actionscript 3, AS3, Adobe AIR
Starling handbook Preview - Gamua, Starling Framework, Actionscript 3, AS3, Adobe AIR
Sie wollen auch ein ePaper? Erhöhen Sie die Reichweite Ihrer Titel.
YUMPU macht aus Druck-PDFs automatisch weboptimierte ePaper, die Google liebt.
Figure 4. <strong>Starling</strong>’s coordinate system has its root at the top left.<br />
We also accessed the stage object and queried its height. The Stage describes the area to which<br />
everything is rendered; it is the very root of the display list (and parent of the Game instance we are<br />
working with right now).<br />
Organizing the Code<br />
It’s nice that there is something on the screen now — but before going on, we need to ponder a little<br />
bit about how we’re going to organize all of the code we’re going to write.<br />
Of course, we could put all of our game elements right into the Game class, but that’s going to get<br />
messy quickly. Instead, it’s a good idea to split the game up into logical units; each with a very<br />
limited responsibility.<br />
After all, we’re not only going to create this landscape with the flying bird, but also a title screen,<br />
maybe a leaderboard, etc. But how should we organize all these elements?<br />
Introducing: The Sprite!<br />
You have already seen this class before: our Game class is extending Sprite. This class is one of the<br />
most important building blocks within <strong>Starling</strong>. It’s a container that can group together multiple<br />
elements.<br />
Here’s a simple example showing a typical use-case of a sprite:<br />
var body:Image = ...;<br />
var tail:Image = ...;<br />
var beak:Image = ...;<br />
var bird:Sprite = new Sprite();<br />
bird.addChild(body);<br />
bird.addChild(tail);<br />
bird.addChild(beak);<br />
addChild(bird);<br />
The bird object now contains body, tail and beak, grouped together in one object. When you want to<br />
8