starling 1.3,Hi-ReS-Stats
FlashDevelop设置
Project->Properties ->Output->Platform->Flash Player->11.5 ->Classpaths->Add Classpath->(starling和Stats的src文件夹)
程序入口
[SWF(frameRate="60", width="800", height="600", backgroundColor="0x333333")] public class Main extends Sprite { private var mStarling:Starling; public function Main():void { if (stage) init(); else addEventListener(Event.ADDED_TO_STAGE, init); } private function init(e:Event = null):void { removeEventListener(Event.ADDED_TO_STAGE, init); this.addChild(new Stats()); mStarling = new Starling(Game, stage); //Game继承自starling.display.Sprite mStarling.antiAliasing = 1; mStarling.start(); } }
代码自动生成
this.addEventListener(Event.ADDED_TO_STAGE, onAddedToStage); 右键onAddedToStage->Refactor->Code Generator->Generate Event handler
版本控制
Setting->SourceControl->SVN ->Enable SVN->True ->SVN Path->(SlikSvn\bin\svn.exe) ->TortoiseSVN Proc Path->(TortoiseSVN\bin\TortoiseProc.exe)
1. 创建项目repo目录,右键->TortoiseSVN->Create repository here->Create folder structure。 2. 项目右键->Shell Menu...->TortoiseSVN->Import...->URL of repository(项目repo目录/trunk)。 3. 项目右键->Shell Menu...->SVN Checkout...->URL of repository(项目repo目录/trunk)。 4. Source Control->...
Sprite Sheet(Texture Atlas)
TexturePacker->Sparrow
内嵌资源
public class Assets { [Embed(source="../media/graphics/bgWelcome.jpg")] public static const BgWelcome:Class; [Embed(source="../media/graphics/mySpritesheet.png")] public static const AtlasTextureGame:Class; [Embed(source="../media/graphics/mySpritesheet.xml", mimeType="application/octet-stream")] public static const AtlasXmlGame:Class; private static var gameTextures:Dictionary = new Dictionary(); private static var gameTextureAtlas:TextureAtlas; public static function getTexture(name:String):Texture { if (gameTextures[name] == undefined) { var bitmap:Bitmap = new Assets[name](); //Assets[name]()是什么意思? gameTextures[name] = Texture.fromBitmap(bitmap); } return gameTextures[name]; } public static function getAtlas():TextureAtlas { if (gameTextureAtlas == null){ var texture:Texture = getTexture("AtlasTextureGame"); var xml:XML = XML(new AtlasXmlGame()); gameTextureAtlas = new TextureAtlas(texture, xml); } return gameTextureAtlas; } }
使用资源
private var bg:Image = new Image(Assets.getTexture("BgWelcome")); private var heroArt:MovieClip = new MovieClip(Assets.getAtlas().getTextures("fly_"), 20); starling.core.Starling.juggler.add(heroArt);
自定义事件
public class NavigationEvent extends Event { public static const CHANGE_SCREEN:String = "changeScreen"; public var params:Object; public function NavigationEvent(type:String, _params:Object = null, bubbles:Boolean=false) { super(type, bubbles); this.params = _params; } }
派发事件
this.dispatchEvent(new NavigationEvent(NavigationEvent.CHANGE_SCREEN, {id: "play"}, true)); //冒泡,让父容器处理事件。
处理事件
private function onChangeScreen(event:NavigationEvent):void { switch (event.params.id) { case "play": screenWelcome.disposeTemporarily(); screenInGame.initialize(); break; } }
单位变换
deg2red()
碰撞检测
if (obstacleToTrack.bounds.intersects(hero.bounds))
Embedded Fonts
[Embed(source="../media/fonts/embedded/BADABB__.TTF", fontFamily="MyFontName", embedAsCFF="false")] public static var MyFont:Class;
//使用 private var scoreText:TextField = new TextField(300, 100, "Score: 0", "MyFontName", 24, 0xffffff);
Bitmap Fonts
[Embed(source="../media/fonts/myFont.png")] public static const FontTexture:Class; [Embed(source="../media/fonts/myFont.fnt", mimeType="application/octet-stream")] public static const FontXML:Class; private static var myFont:BitmapFont; public static function getFont():BitmapFont { if (myFont == null) { var fontTexture:Texture = Texture.fromBitmap(new FontTexture()); var fontXML:XML = XML(new FontXML()); myFont = new BitmapFont(fontTexture, fontXML); starling.text.TextField.registerBitmapFont(myFont); } return myFont; }
//使用 private var scoreText:TextField = new TextField(300, 100, "Score: 0", Assets.getFont().name, 24, 0xffffff);
粒子系统
[Embed(source="../media/particles/particleCoffee.pex", mimeType="application/octet-stream")] public static var ParticleXML:Class; [Embed(source="../media/particles/texture.png")] public static var ParticleTexture:Class;
//使用 private var particle:PDParticleSystem; particle = new PDParticleSystem(XML(new AssetsParticles.ParticleXML()), Texture.fromBitmap(new AssestsParticles.ParticleTexture())); Starling.juggler.add(particle); particle.start();