This series is a translation of the introducing Starling PDF, which is reproduced in a log of the Adobe Developer Center, with the address http://www.adobe.com/cn/devnet/flashplayer/articles/ Introducing_starling.html
Starling is an ActionScript 3 2D framework developed on Stage3D APIs (available for Flash Player 11 and Adobe AIR 3 desktops). Starling is designed for game development, but you can apply it to many other applications. Without involving low-level Stage3D APIs, Starling makes it possible to write applications with fast GPU acceleration capabilities.
Most Flash developers want to take advantage of this ability to improve GPU acceleration (by using Stage3D technology) without having to write such a high-level framework and delve deeper into low-level Stage3D APIs. Starling is designed entirely based on Flash Player APIs and abstracts the complexity of Stage3D (Molehill). So everyone can see the intuitive program.
Starling is designed for ActionScript 3 developers, especially those involved in 2D game development. Before using ActionScript 3, you must have a basic understanding of it. Because Starling is lightweight, flexible, and easy to use, you can also apply it to other project requirements, such as UI programming. This framework requires the design to be as intuitive as possible, so any Java™ or. Net™ developers can start using it right away.
Starling Usage Overview
The Starling is intuitive and easy to use. Flash and Flex developers can quickly understand it because it follows most of the ACTIONSCRIPT rules and abstracts the complexities of low-level Stage3D APIs. Starling uses familiar concepts such as the DOM display list, the event model, and familiar APIs such as MovieClip, Sprite, TextField, rather than relying on such things as vertex buffering (vertices buffer), The Perspective matrix (Perspective matrices), the shader program (shader programs), and the combined bytecode (assembly bytecode) are encoded.
Starling is very light in many areas. The number of classes is limited (approximately 80k of code). It has no external dependencies other than Flash Player 11 or AIR 3 (and mobile support used in future releases). These factors make your application small and make your workflow simple.
Starling is free to use and vibrant. It is licensed under the simplified BSD license, so you can use it for free, even in commercial applications. We use it every day and we rely on an active team to constantly refine it.
In a background operation, Starling uses Stage3D apis-, which are low-level GPU APIs that run on the desktop based on OpenGL ES2 on the mobile device and on the on-screen basis of OpenGL and DirectX. It is important to note that Starling is the ActionScript 3 port of Sparrow, which equates to an ISO library based on OpenGL ES2 APIs (see Figure 1):
Figure 1. Stage3D (Molehill) layered on top of Starling
Starling has re-created many of the APIs that Flash developers are familiar with. The graphical element APIs exposed through Starling are listed (see Figure 2).
Figure 2. Starling supports Displayobject inheritance
It may seem odd to create 2D content based on 3D GPU APIs. When it comes to Stage3D APIs, many people think that these APIs are strictly limited to 3D content. This is actually a misunderstanding of the name: if it's called Stage3D, how can you use it to create 2D elements? Illustrates the issue of drawing MovieClip capabilities using the Drawtriangles API (see Figure 3).
Figure 3. Can I create a 2D movie clip using the Drawtriangles API?
The GPU is highly efficient and can draw triangles quickly. By using the Drawtriangles API, you can draw two triangles, then pick a texture and apply it to the triangle using a UV map. This creates a four-sided shape with a texture that represents a sprite. By updating the texture of a triangle on each frame, the final result is a MovieClip.
Fortunately, we do not need to use Starling through these details. You just need to provide the number of frames and provide them to a Starling MovieClip, which is all you need to do (see Figure 4).
Figure 4. Using the Drawtriangles API and a textured quad, you can create a 2D graphic
To better understand how Starling reduces complexity, check the code you have to write to make it easy to display simple, textured quads with low-level Stage3D APIs.
//Create the verticesvarvertices:vector.< Number> = vector.< Number> ([-0.5,-0.5,0, 0, 0,//x, y, Z, u, v-0.5, 0.5, 0, 0, 1,0.5, 0.5, 0, 1, 1,0.5,-0.5, 0, 1, 0]); //create the buffer to upload the verticesvarVertexbuffer:vertexbuffer3d = Context3d.createvertexbuffer (4, 5); //Upload the verticesVertexbuffer.uploadfromvector (vertices, 0, 4); //create the buffer to upload the indicesvarIndexbuffer:indexbuffer3d = Context3d.createindexbuffer (6); //Upload the indicesIndexbuffer.uploadfromvector (Vector.<uint> ([0, 1, 2, 2, 3, 0]), 0, 6); //Create the bitmap texturevarBitmap:bitmap =NewTexturebitmap ();//create the texture bitmap to upload the bitmapvarTexture:texture =context3d.createtexture (Bitmap.bitmapData.width, Bitmap.bitmapData.height, Context3dtextureformat.bgra,false); //Upload the bitmapTexture.uploadfrombitmapdata (bitmap.bitmapdata);//Create the Mini assemblervarVertexshaderassembler:agalminiassembler =NewAgalminiassembler ();//Assemble the vertex shadervertexshaderassembler.assemble (Context3dprogramtype.vertex,"M44 op, va0, vc0\n"+//Pos to Clipspace"mov v0, va1" //Copy UV); //assemble the fragment shaderfragmentshaderassembler.assemble (context3dprogramtype.fragment,"Tex Ft1, V0, Fs0 <2d,linear, nomip>;\ N "+"mov oc, FT1"); //Create the Shader programvarProgram:program3d =Context3d.createprogram ();//upload the vertex and fragment shadersprogram.upload (Vertexshaderassembler.agalcode, fragmentshaderassembler.agalcode);//Clear the bufferContext3d.clear (1, 1, 1, 1 ); //set the vertex bufferContext3d.setvertexbufferat (0, vertexbuffer, 0, Context3dvertexbufferformat.float_3); Context3d.setvertexbufferat (1, VertexBuffer, 3, context3dvertexbufferformat.float_2); //Set the textureContext3d.settextureat (0, texture); //Set the Shaders programContext3d.setprogram (program);//Create a 3D matrixvarM:matrix3d =NewMatrix3D ();//apply rotation to the matrix to rotate vertices along the Z axisM.appendrotation (Gettimer ()/, Vector3d.z_axis);//Set the program constants (matrix here)Context3d.setprogramconstantsfrommatrix (Context3dprogramtype.vertex,0, M,true); //Draw the Trianglescontext3d.drawtriangles (indexbuffer);//present the pixels to the screenContext3d.present ();
http://www.techsite.cn/?p=49
"Go" Starling 2D Framework Introduction (i)