Setting Up Your Scene
But enough introduction—let’s dig into the code and see what this
little bird can do. Starling is very easy to setup. First, a Starling
object needs to be created and added
to your main class.
Warning
Starting from now, when referring to objects like MovieClip, Sprite, and so on, we will imply the Starling APIs and not the native ones from the Flash Player, unless specificed explicitly.
The Starling constructor expects multiple arguments. Here is the signature:
public
function
Starling
(
rootClass
:
Class
,
stage
:
flash
.
display
.
Stage
,
viewPort
:
Rectangle
=
null
,
stage3D
:
Stage3D
=
null
,
renderMode
:
String
=
"auto"
)
Actually, the first two are the only ones really used commonly.
The rootClass
argument expects a
reference to a class extending starling.display.Sprite
and as a second
argument, our stage:
package
{
import
flash
.
display
.
Sprite
;
import
flash
.
display
.
StageAlign
;
import
flash
.
display
.
StageScaleMode
;
import
starling
.
core
.
Starling
;
[
SWF
(
width
=
"1280"
,
height
=
"752"
,
frameRate
=
"60"
,
backgroundColor
=
"#002143"
)]
public
class
Startup
extends
Sprite
{
private
var
mStarling
:
Starling
;
public
function
Startup
()
{
stage
.
align
=
StageAlign
.
TOP_LEFT
;
stage
.
scaleMode
=
StageScaleMode
.
NO_SCALE
;
// create our Starling instance
mStarling
=
new
Starling
(
Game
,
stage
);
// show the stats window (draw calls, memory)
mStarling
.
showStats
=
true
;
// set anti-aliasing (higher the better quality but slower performance)
mStarling
.
antiAliasing
=
1
;
// start it!
mStarling
.
start
();
}
}
}
-
Here’s our
Get Introducing Starling now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.