O'Reilly logo

Introducing Starling by Thibault Imbert

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How

Behind the scenes, Starling uses the Stage3D APIs, which are low-level GPU APIs running on top of OpenGL and DirectX on desktop and OpenGL ES2 on mobile devices. As a developer, you have to know that Starling is the ActionScript 3 port of Sparrow (http://www.gamua.com/starling), the equivalent library for iOS relying on OpenGL ES2 APIs (Figure 1-1).

Starling layer on top of Stage3D (Molehill)

Figure 1-1. Starling layer on top of Stage3D (Molehill)

Starling re-creates many APIs that Flash developers are already familiar with. Figure 1-2 illustrates the APIs exposed by Starling when it comes to graphical elements.

DisplayObject inheritance

Figure 1-2. DisplayObject inheritance

Many people think that the Stage3D APIs are strictly limited to 3D content (and, to be fair, the name is a bit confusing), but you can in fact also create 2D content with them.

Figure 1-3 illustrates the idea. How can we draw something like a MovieClip with the drawTriangles API?

drawTriangles and 2D?

Figure 1-3. drawTriangles and 2D?

Actually, it is very simple. GPU are extremely efficient at drawing triangles, so the drawTriangles API will draw two triangles, and we will then sample a texture and apply it to the triangles using UV mapping. We will then end up with our textured quad, which represents our sprite. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required