starling1.2 游戏思路<1>

最近把hungry hero看了,

也看了一下和别人交流的游戏。

决定还是系统过一遍吧,把一般游戏基本思路写下来

 

开发工具   :

1.flash builder 4.7

2.Starling

 

开始

新建-actionScript手机项目  在xml加入

 

 <renderMode>direct</renderMode>

 

开启GPU加速

 

第一步:游戏图标 

在生成的xml中找到icon项,如下

 

    <!-- <icon>
        <image16x16></image16x16>
        <image29x29></image29x29>
        <image32x32></image32x32>
        <image36x36></image36x36>
        <image48x48></image48x48>
        <image50x50></image50x50>
        <image57x57></image57x57>
        <image58x58></image58x58>
        <image72x72></image72x72>
        <image100x100></image100x100>
        <image114x114></image114x114>
        <image128x128></image128x128>
        <image144x144></image144x144>
        <image512x512></image512x512>
        <image1024x1024></image1024x1024>
    </icon> -->

 

在该位置设置图标。并把自己制作好的图标放到 src目录下

例如:

<icon>
<image114x114>Icon@2x.png</image114x114>
</icon>

 这样子你在打包ipa的时候就会生成这个图标啦。当然面对不同分辨率下,自己制作不同的就可以了~ 图标设置就是这么简单~~

 

第二 :开启Starling

  

 1 package
 2 {
 3     import flash.display.Sprite;
 4     
 5     import starling.core.Starling;
 6     
 7     [SWF(frameRate="60", width="960", height="640", backgroundColor="#333333")]
 8     public class GasBoyTest extends Sprite
 9     {
10         private var myStarling:Starling;
11         public function GasBoyTest()
12         {
13             super();
14             
15             //Starling.multitouchEnabled = true;
16             myStarling = new Starling(Game, stage);
17             //抗锯齿
18             myStarling.antiAliasing = 1;
19             //显示帧率
20             myStarling.showStats = true;
21             //开启
22             myStarling.start();
23             
24         }
25     }
26 }

  

 第三步: 设计游戏框架

 

我们把游戏分为四块  :1.进入游戏界面  2.欢迎界面3. 关于界面4.游戏结束界面

对应的类如下:

 

private var InGameScreen:InGame;
private var WelcomeScreen:Welcome;
private var AboutScreen:About;
private var OverScreen:Over;

我们分别把这些类放screens文件夹下

 

并在Game类中声明 这些类

Game类

package
{
    
    import screens.About;
    import screens.InGame;
    import screens.Over;
    import screens.Welcome;
    
    import starling.display.Sprite;
    import starling.events.Event;
    
    public class Game extends Sprite
    {
        private var InGameScreen:InGame;
        private var WelcomeScreen:Welcome;
        private var AboutScreen:About;
        private var OverScreen:Over;
        
        public function Game()
        {
            super();
            this.addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
        }
        
        private function onAddedToStage(event:Event):void
        {
            this.removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);

} } }

  

 前期工作准备好了。这是我们需要写一个 用于获取素材的类 Assets.as 这个类能获取单张图片以及sprite sheet,当然为了后期的安排,我们也把获取字体和粒子写到这个类中。

其实这个方法在starling-textures-下就有texturesatlas和texture方法,下面只是把这两个方法做到一起变成asset.as而已。个人觉得方便而已。其实也是间接用starling中的两个类。

这样子 assets.as这个获取素材类  就有四个方法 1. 获取单张图片 2.获取sprite sheet 3.获取字体 4.获取粒子

单张图片我们就直接Embed定义类通过名字获取,而sprite sheet我们就通过xml以及对应的sprite sheet坐标去获取图片动画。

 

//获取字体
         public static function getFont():BitmapFont
         {
             var fontTexture:Texture = Texture.fromBitmap(new FontTexture());
             var fontXML:XML = new XML(new FontXML);
             
             var font:BitmapFont = new BitmapFont(fontTexture, fontXML);
             TextField.registerBitmapFont(font);
             
             return font;
             
         }
         
 //获取单张图片
         public static function getTexture(name:String):Texture
         {
             if (gameTexture[name] == undefined)
             {
                 var bmp:Bitmap = new Assets[name]();
                 gameTexture[name] = Texture.fromBitmap(bmp);
             }
             
             return gameTexture[name];
         }
         
 //获取sprite sheet
         public static function getTextureAtlas():TextureAtlas
         {
             if (gameTextureAtlas == null)
             {
                 var texture:Texture = getTexture("spriteSheets");
                 
                 var xml:XML = XML(new spriteSheetsXML());
                 
                 gameTextureAtlas = new TextureAtlas(texture, xml); 
             }
             return gameTextureAtlas;
         }
 //获取粒子
      public static function getParticleXML(name:String):XML
        {
            var xml:XML;
            
            xml = XML(new Assets[name]());
            
            return xml;
        }

 

假设我们要获取制作好的sprite sheet中的图片

那么我们可以这样,例如获取按钮图片:

startBtn = new Button(Assets.getTextureAtlas().getTexture("start_btn"));

walkShoot = new MovieClip(Assets.getTextureAtlas().getTextures("walkShoot_"), 10);

 

图片获取差不多就是这样了~

 

 第四步: 游戏界面切换

starling1.2 游戏边写边做<2>

 

 

 

posted @ 2012-12-07 22:59  洪小瑶  阅读(392)  评论(0编辑  收藏  举报