Posted By

line-effect on 11/07/12


Tagged

Stage3D Starling2D


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

configuration


Setup Starling, And Start the Engine


 / Published in: ActionScript 3
 

Starling2D Engine is using the power of FLASH STAGE3D to create 2D games so you can use alot of sprites, particles .... with no impact on your SWF performance.

To start the Engine, you have to download the last version of Starling from this site: http://gamua.com/starling/download/

create a new action script project inside flash builder and add the SWC or the source files to your project

now create 2 class, one of them is to start the starling engine, and the 2nd class will be targeted with the 1st class with its CLASS NAME to run the 2nd class on STAGE3D.

  1. The 1st CLASS to START THE STARLING2D ENGINE:
  2. package
  3. {
  4. import flash.display.Sprite;
  5. import flash.display.StageAlign;
  6. import flash.display.StageScaleMode;
  7.  
  8. import net.hires.debug.Stats;
  9. import starling.core.Starling;
  10.  
  11. // the properties of the SWF FILE
  12. [SWF(frameRate="60",width="780",height="680",backgroundColor="#002143")]
  13.  
  14. public class StarlingTest extends Sprite
  15. {
  16. // We have to create a Variable for the Starling FrameWork to start
  17. private var intilStarling:Starling;
  18.  
  19. public function StarlingTest()
  20. {
  21. /*
  22. Status Class for FPS
  23. Stage Aligns
  24. Create our Starling Instance
  25. Set the Anti-Aliasing (Higher better but slow performance)
  26. Note: Anti-Aliasing Values:
  27. 0 = no, 2 = Minimal, 4 = high, 16 = Very High
  28. Then we start the FrameWork
  29. */
  30.  
  31. stage.align = StageAlign.TOP_LEFT;
  32. stage.scaleMode = StageScaleMode.NO_SCALE;
  33. intilStarling = new Starling(Main,stage); //MAIN IS OUR GAME OR APP MAIN CLASS NAME
  34. intilStarling.antiAliasing = 2;
  35. intilStarling.start();
  36. }
  37. }
  38. }
  39.  
  40. The 2nd CLASS:
  41. NOTE: THE NAME OF THIS CLASS SHOULD BE THE SAME AS THE CLASS NAME TARGETED BY STARLING.
  42.  
  43. package
  44. {
  45. import starling.core.Starling;
  46. import starling.display.DisplayObject;
  47. import starling.display.MovieClip;
  48. import starling.display.Sprite;
  49. import starling.events.Event;
  50. import starling.textures.Texture;
  51. import starling.textures.TextureAtlas;
  52.  
  53. public class Main extends Sprite
  54. {
  55. // XML Data
  56. [Embed(source="SpriteSheet.xml",mimeType="application/octet-stream")]
  57. private var AtlasXML:Class;
  58.  
  59. // Texture File
  60. [Embed(source="SpriteSheet.png")]
  61. private var AtlasTexture:Class;
  62.  
  63. private var mc:MovieClip;
  64.  
  65. public function Main()
  66. {
  67. addEventListener(Event.ADDED_TO_STAGE,onAdded);
  68. }
  69.  
  70. private function onAdded(e:starling.events.Event):void
  71. {
  72. CreateMovieClip();
  73. }
  74.  
  75. private function CreateMovieClip():void
  76. {
  77. // Create a Texture Var using yout Photo
  78. var texture:Texture = Texture.fromBitmap(new AtlasTexture());
  79. var xml:XML = new XML(new AtlasXML());
  80. var atlas:TextureAtlas = new TextureAtlas(texture,xml);
  81.  
  82. mc = new MovieClip(atlas.getTextures("SpriteSheet"),20);
  83. addChild(mc);
  84.  
  85. // To start Animating the MovieClip
  86. Starling.juggler.add(mc);
  87. }
  88. }
  89. }

Report this snippet  

You need to login to post a comment.