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

贴图

在游戏中,贴图可以用来显示文字或者图片等内容。比如:显示“好”,“太棒了”,也可以用来显示生命条。

我们的定义了一个 Pinup 类来表示贴图,他是一个很简单的类。

internal abstract class Pinup
: Spirit
{ protected Pinup ( IPlayScene scene, int type, Vector2 location, string movieName, float speed, int angle, int width, int height, double destroySecond )
: base ( scene, type, location, movieName,
null,
speed,
angle,
null,
width, height, destroySecond,
true,
false,
false, )
{ } protected override Vector2 getMovieLocation ( )
{ return this.Location - this.halfSize; } protected override void updateSpeed ( )
{
this.xSpeed = Calculator.Cos ( this.angle ) * this.speed;
this.ySpeed = Calculator.Sin ( this.angle ) * this.speed; base.updateSpeed ( );
} protected override void move ( )
{
this.Location.X += this.xSpeed;
this.Location.Y += this.ySpeed;
} }

由于这个类中没有特别的成员,所以大家可以参照其他 Spirit 类的解释。

贴图管理器

PinupManager 类派生自类 SpiritManager<T>,默认的绘制顺序是 4000。

internal class PinupManager
: SpiritManager<Pinup>
{ internal PinupManager ( )
: base ( )
{ } }

示例

场景 SceneT18 是 SceneT17 的扩展,除了有 SceneT17 的功能,还将显示一个贴图。

我们定义了类 MyHit 类,他表示一个贴图,当小鸟第一次被子弹击中后,我们将显示 MyHit。

internal class MyHit
: Pinup
{ internal MyHit ( IPlayScene scene, Vector2 location )
: base ( scene, , location, "mypinup", , ,
, , )
{ } }

然后,我们定义了一些字段。

private PinupManager pinupManager;

private bool is1Hit = false;

字段 is1Hit 用来表示小鸟是否被第一次击中。

internal SceneT18 ( )
: base ( Vector2.Zero, GestureType.None, "background1",
new Resource[] {
new Resource ( "bird2.image", ResourceType.Image, @"image\bird2" ),
new Resource ( "bullet.image", ResourceType.Image, @"image\bullet" ),
new Resource ( "item.image", ResourceType.Image, @"image\item" ),
new Resource ( "pinup.image", ResourceType.Image, @"image\pinup1" ),
new Resource ( "go.image", ResourceType.Image, @"image\button1" ),
},
new Making[] {
new Movie ( "bird", "bird2.image", , , , "live",
new MovieSequence ( "live", true, new Point ( , ), new Point ( , ) )
),
new Movie ( "mybutton", "bullet.image", , , , "b",
new MovieSequence ( "b", new Point ( , ) )
),
new Movie ( "myitem", "item.image", , , , "i",
new MovieSequence ( "i", new Point ( , ) )
),
new Movie ( "mypinup", "pinup.image", , , , "p",
new MovieSequence ( "p", new Point ( , ) )
),
new Button ( "b.go", "go.image", "GO", new Vector2 ( , ), , , new Point ( , ) ),
}
)
{
// ... this.pinupManager = new PinupManager ( );
this.pinupManager.Scene = this; // ...
}

在 SceneT18 的构造函数中,我们将创建了类 PinupManager。

private void bulletHitTesting ( object sender, BulletHitAreaEventArgs e )
{ if ( !this.bird.IsDied && e.HitArea.HitTest ( this.bird.HitArea ) )
{
e.IsHit = true;
e.Targets = new IAssailable[] { this.bird }; if ( !this.is1Hit )
{
this.is1Hit = true;
this.pinupManager.Append ( new MyHit ( this, new Vector2 ( , ) ) );
} } }

我们根据字段 is1Hit 来决定是否显示贴图,而 MyHit 的显示时间为 1 秒。

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

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

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

QQ 群 213685539

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

最新文章

  1. python 自带的ide 不能保存文件
  2. PostgreSQL configuration file postgresql.conf recommanded settings and how it works
  3. linux下文件系统类型的学习
  4. ZOJ-2366 Weird Dissimilarity 动态规划+贪心
  5. 深入理解JavaScript闭包(closure)
  6. 【iOS 7】使用UIScreenEdgePanGestureRecognizer实现swipe to pop效果
  7. linux可重入、异步信号安全和线程安全
  8. `~!$^*()[]{}\|;:&#39;&quot;,&lt;&gt;/?在英文怎么读?
  9. Hibernate 关联关系映射实例
  10. Android UI ActionBar功能-启动ActionBar
  11. XDU 1284 寻找礼物
  12. TFS在项目中DevOps落地进程(下)
  13. 网站添加icon
  14. Python全栈开发之路 【第八篇】:面向对象编程设计与开发(2)
  15. libevent的入门学习-库的安装【转】
  16. vue教程3-02 vue动画
  17. 【Python】opencv显示图像
  18. 模拟生成环境的MySQL安装方法-通用二进制方式安装
  19. Python练习笔记——斐波那契数列
  20. K:括号分隔符匹配问题

热门文章

  1. Linux命令行环境与桌面环境护切换
  2. centOS7虚拟机连接大网
  3. Js面向对象之观察者模式
  4. 汇编:jmp系列跳转指令总结
  5. POJ1061 青蛙的约会 __一维世界的爱情
  6. java 串口通信实现流程
  7. Spring,FetchType.LAZY和FetchType.EAGER什么区别?
  8. noip模拟赛#24
  9. 让你不再害怕指针——C指针详解(经典,非常详细)
  10. Python实现进度条小程序