欢迎访问移动开发之家(rcyd.net),关注移动开发教程。移动开发之家  移动开发问答|  每日更新
页面位置 : > > 内容正文

使用 SpiritManager 类管理在 XNA 游戏中的精灵(十四)

来源: 开发者 投稿于  被查看 6567 次 评论:163

使用 SpiritManager 类管理在 XNA 游戏中的精灵(十四)


平方已经开发了一些 Windows Phone 上的一些游戏,算不上什么技术大牛。在这里分享一下经验,仅为了和各位朋友交流经验。平方会逐步将自己编写的类上传到托管项目中,没有什么好名字,就叫 WPXNA 吧,最后请高手绕道而行吧,以免浪费时间。(为了突出重点和减少篇幅,有些示例代码可能不够严谨。)

SpiritManager<T>

SpiritManager<T> 包含了一些管理精灵的方法,我们还可以派生很多的管理类,比如:子弹管理类。下面是 SpiritManager<T> 的成员。

字段 Spirits 表示管理器所管理的精灵,字段 defaultOrder 表示精灵的绘制次序。字段 Scene 可以让我们访问场景中的内容。以后,我们还会将其替换为 IPlayScene。

方法 Append 用来将精灵添加到管理器,我们将会精灵设置 Destroyed 事件,在这个事件中,被摧毁的精灵将被从管理器移除。在 remove 方法中,我们将注销 Destroyed 事件。

   SpiritManager<T>  List<T> Spirits =  List<T>  
     (  SpiritManager ( .defaultOrder =   spiritDestroyed ( .remove ( sender   Append ( IList<T> (  != ( T spirit  .Append ( spirit,    Append ( T spirit, +=  ( order !=  && spirit.DrawOrder == = -=    =  ( T spirit   

 

示例

场景 SceneT15 和之前的 SceneT14 是类似,我们同样有一个 Bird 类,但是我们增加了一个 BirdManager 类,这个类从 SpiritManager<T> 派生。

BirdManager 有两个方法,Go 方法将调用所有的 Bird 类的 Go 方法,Stop 方法将调用所有的 Bird 类的 Stop 方法。

 <Bird>  ( Bird bird    ( Bird bird  

SceneT15 同样包含了两个按钮,当点击两个按钮时,将分别调用 BirdManager 的 Go 和 Stop 方法。在 SceneT15 构造函数中,我们创建 BirdManager 类,并需要设置字段 Scene。

在 LoadContent 方法中,我们将两个 Bird 类添加到 BirdManager 中。而在 UnloadContent 方法中,我们调用 BirdManager 的 RemoveAll 方法来删除所有的小鸟。

在 Dispose 方法中,我们将调用 BirdManager 的 Dispose 方法。

     ( Vector2.Zero, GestureType.None,  Resource ( , ResourceType.Image,  Resource ( , ResourceType.Image,  Resource ( , ResourceType.Image,  Movie ( , , , , ,  MovieSequence ( , ,  Point ( ,  ),  Point ( ,  MovieSequence ( , ,  Point ( ,  Button ( , , ,  Vector2 ( ,  ), , ,  Point ( ,  Button ( , , ,  Vector2 ( ,  ), , ,  Point ( , .birdManager = .birdManager.Scene = .goButton = .makings[  ] .stopButton = .makings[  ] .goButton.Selected += .stopButton.Selected +=   goButtonSelected (   stopButtonSelected (   .birdManager.Append (  Bird ( ,  Vector2 ( , .birdManager.Append (  Bird ( ,  Vector2 ( ,     

 

本期视频 http://v.youku.com/v_show/id_XNTgyMDUwMTg0.html

项目地址 http://wp-xna.googlecode.com/
更多内容 WPXNA

平方开发的游戏 http://zoyobar.lofter.com/

QQ 群 213685539

欢迎访问我在其他位置发布的同一文章:http://www.wpgame.info/post/decc4_76f27b

相关频道:

用户评论