Your SlideShare is downloading. ×
Developing 2D Games with Stage3D
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Saving this for later?

Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime - even offline.

Text the download link to your phone

Standard text messaging rates apply

Developing 2D Games with Stage3D

2,295
views

Published on

This deck covers the basic setup of Stage3D and how you can leverage it for 2D game development (specifically using the Starling framework).

This deck covers the basic setup of Stage3D and how you can leverage it for 2D game development (specifically using the Starling framework).

Published in: Technology, Art & Photos

0 Comments
5 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,295
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
25
Comments
0
Likes
5
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide
  • Trust Lee to pick these images :p
  • Transcript

    • 1. •••••
    • 2. •••
    • 3. • • • • •
    • 4. ••••
    • 5. // 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 verticesvar vertexbuffer:VertexBuffer3D = context3D.createVertexBuffer(4, 5);// upload the verticesvertexbuffer.uploadFromVector(vertices, 0, 4);// create the buffer to upload the indicesvar indexbuffer:IndexBuffer3D = context3D.createIndexBuffer(6);// upload the indicesindexbuffer.uploadFromVector (Vector.<uint>([0, 1, 2, 2, 3, 0]), 0, 6);// create the bitmap texturevarbitmap:Bitmap = new TextureBitmap();// 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 = new AGALMiniAssembler();// assemble the vertex shadervertexShaderAssembler.assemble( Context3DProgramType.VERTEX,"m44 op, va0, vc0n" + // pos to clipspace"mov v0, va1" // copy uv);
    • 6. varfragmentShaderAssembler :AGALMiniAssembler = new AGALMiniAssembler();// assemble the fragment shaderfragmentShaderAssembler.assemble( Context3DProgramType.FRAGMENT,"tex ft1, v0, fs0 <2d,linear, nomip>;n" +"movoc, ft1");// create the shader programvar program: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 matrixvar m:Matrix3D = new Matrix3D();// apply rotation to the matrix to rotate vertices along the Z axism.appendRotation(getTimer()/50, 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();
    • 7. // create a Texture object out of an embedded bitmapvar _texture:Texture = Texture.fromBitmap ( new EmbeddedBitmap() );// create an Image object our of the Texturevar _image:Image = new Image(_texture);// set the properties_image.pivotX = 50;_image.pivotY = 50;_image.x = 300;_image.y = 150;_image.rotation = Math.PI/4;// display itaddChild(_image);