FLEX和Actionscript开发FLASH游戏7-4


FLEX和Actionscript开发FLASH游戏7-4
2010年11月24日
  使用FLEX和Actionscript开发FLASH 游戏-位图动画 
  Enemy.as package {     import flash.geom.Point;     import mx.core.*;     public class Enemy extends AnimatedGameObject     {         static public var pool:ResourcePool=new ResourcePool(NewEnemy);         protected var logic:Function=null;         protected var speed:Number=0;         static public function NewEnemy():Enemy         {             return new Enemy();         }         public function Enemy()         {             super();         }         public function startupBasicEnemy(graphics:GraphicsResource,positi on:Point,speed:Number):void         {             super.startupAnimatedGameObject(graphics,position, ZOrders.PlayerZOrder);             logic=basicEnemyLogic;             this.speed=speed;             this.collisionName=CollisionIdentifiers.ENEMY;         }         override public function shutdown():void         {             super.shutdown();             logic=null;         }         override public function enterFrame(dt:Number):void         {             super.enterFrame(dt);             if(logic!=null)                 logic(dt);         }         protected function basicEnemyLogic(dt:Number):void         {             if(position.y>Application.application.height+graphi cs.bitmap.height)                this.shutdown();             position.y+=speed*dt;         }         override public function collision(other:GameObject):void         {             var animatedGameObject:AnimatedGameObject=AnimatedGame Object.pool.ItemFromPool as AnimatedGameObject;             animatedGameObject.startupAnimatedGameObject(Resou rceManager.BigExplosionGraphics,new Point(             position.x+graphics.bitmap.width/graphics.frames/2 -            ResourceManager.BigExplosionGraphics.bitmap.width/ ResourceManager.BigExposionGraphics.frames/2,             position.y+graphics.bitmap.height/2-             ResourceManager.BigExplosionGraphics.bitmap.height /2),             ZOrders.PlayerZOrder,ture);             this.shutdown();         }     } }  通过继承AnimatedGameObject类而不是GameObject类我们让敌机类动画化。这也需要在我们的startup函数中调用super.startupAnimatedGameObject而不是super.startupGameObject。
  其它的唯一的变化是在collision函数里,在这里我们生成了AnimatedGameObject来描绘爆炸。注意我们在构造器中设置playOnce为真。这意味着爆炸将被产生,然后在屏幕里移除其之前将呈现一次爆炸特效。
  动画给游戏增加了一个整个的新的级别。通过生成AnimatedGameObject类我们现在能够快速简单地给游戏增加动画对象。现在只差一件事就是声效,我们将在第八部分增加。
  在http://flexfighters.sourceforge.net/flexfighters7. html处可查看最终效果,从https://sourceforge.net/project/showfiles.php?grou p_id=241490&package_id=293860&release_id=633834处可下载资源。

猜你喜欢

转载自rns64rns.iteye.com/blog/1571757
7-4
今日推荐