平方已经开发了一些 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

使用 Pinup,PinupManager 在 XNA 中创建贴图(十七)的更多相关文章

  1. 使用 NPC,NPCManager 在 XNA 中创建 NPC

    使用 NPC,NPCManager 在 XNA 中创建 NPC 平方已经开发了一些 Windows Phone 上的一些游戏,算不上什么技术大牛.在这里分享一下经验,仅为了和各位朋友交流经验.平方会逐 ...

  2. 使用 Region,RegionManager 在 XNA 中创建特殊区域(十八)

    平方已经开发了一些 Windows Phone 上的一些游戏,算不上什么技术大牛.在这里分享一下经验,仅为了和各位朋友交流经验.平方会逐步将自己编写的类上传到托管项目中,没有什么好名字,就叫 WPXN ...

  3. 使用 NPC,NPCManager 在 XNA 中创建 NPC(十九)

    平方已经开发了一些 Windows Phone 上的一些游戏,算不上什么技术大牛.在这里分享一下经验,仅为了和各位朋友交流经验.平方会逐步将自己编写的类上传到托管项目中,没有什么好名字,就叫 WPXN ...

  4. 使用 Item,ItemManager 在 XNA 中创建物品和道具(十六)

    平方已经开发了一些 Windows Phone 上的一些游戏,算不上什么技术大牛.在这里分享一下经验,仅为了和各位朋友交流经验.平方会逐步将自己编写的类上传到托管项目中,没有什么好名字,就叫 WPXN ...

  5. 使用 Bullet,BulletManager 在 XNA 中创建子弹攻击目标(十五)

    平方已经开发了一些 Windows Phone 上的一些游戏,算不上什么技术大牛.在这里分享一下经验,仅为了和各位朋友交流经验.平方会逐步将自己编写的类上传到托管项目中,没有什么好名字,就叫 WPXN ...

  6. 使用 Spirit 类在 XNA 中创建游戏中的基本单位精灵(十三)

    平方已经开发了一些 Windows Phone 上的一些游戏,算不上什么技术大牛.在这里分享一下经验,仅为了和各位朋友交流经验.平方会逐步将自己编写的类上传到托管项目中,没有什么好名字,就叫 WPXN ...

  7. 使用 Button 类在 XNA 中创建图形按钮(九)

    平方已经开发了一些 Windows Phone 上的一些游戏,算不上什么技术大牛.在这里分享一下经验,仅为了和各位朋友交流经验.平方会逐步将自己编写的类上传到托管项目中,没有什么好名字,就叫 WPXN ...

  8. 使用 Scene 类在 XNA 中创建不同的场景(八)

    平方已经开发了一些 Windows Phone 上的一些游戏,算不上什么技术大牛.在这里分享一下经验,仅为了和各位朋友交流经验.平方会逐步将自己编写的类上传到托管项目中,没有什么好名字,就叫 WPXN ...

  9. 使用 CommandScene 类在 XNA 中创建命令场景(十二)

    平方已经开发了一些 Windows Phone 上的一些游戏,算不上什么技术大牛.在这里分享一下经验,仅为了和各位朋友交流经验.平方会逐步将自己编写的类上传到托管项目中,没有什么好名字,就叫 WPXN ...

随机推荐

  1. 360 so动态脱壳

    环境及工具 手机    : 中兴 U887 系统版本:   Android 2.3.5 工具    :   IDA pro 6.6 .0101Editor 版权声明:未经许可,随便转载 目前so加壳有 ...

  2. Piwik-2.16.1 (OpenLogic CentOS7.2)

    平台: CentOS 类型: 虚拟机镜像 软件包: centos7.2 piwik devops log analysis monitoring open-source 服务优惠价: 按服务商许可协议 ...

  3. pat乙级1051

    当结果中a或者b小于0,大于0.005时,保留两位小数会输出-0.00,但应输出0.00. #include <iostream> #include <math.h> usin ...

  4. IOS 图片剪切(封装数据)

    封装 :生成头像(UIImage (NJ).h / .m @interface UIImage (NJ) /** * 生成头像 * * @param icon 头像图片名称 * @param bord ...

  5. hbase查询基于标准sql规范中间件Phoenix

    Phoenix是个很好的hbase 查询工具,在hbase中安装也很简单,可以按照 http://www.cnblogs.com/laov/p/4137136.html 这个连接中进行配置客户端和服务 ...

  6. 浅谈前端性能优化(二)——对HTTP传输进行压缩

    1.前端性能优化的一点: 对js.css.图片等进行压缩,尽可能减小文件的大小,减少文件下载的时间,从而减少网页响应的时间. 2.前端性能优化的另一点: 对HTTP传输进行压缩,即在js,css.图片 ...

  7. 【BZOJ4540】 [HNOI2016] 序列(莫队)

    点此看题面 大致题意: 求出一个序列的一段区间中所有子序列最小值之和. 莫队 这道题其实是一道莫队题. 但是需要大量的预处理. 预处理 先考虑预处理两个数组\(lst_i\)和\(nxt_i\),分别 ...

  8. GVIM——简直美如画,有没有!

    "========================================== " Author: wklken " Version: 9.1 " Em ...

  9. linux下通过phpize为php在不重新编译php情况下安装模块memcache

    通过phpize为php在不重新编译php情况下安装模块memcache 1. 下载    wget http://pecl.php.net/get/memcache-2.2.4.tgz     解压 ...

  10. 微信公众帐号开发之一(java)

    闲来没事,就记录一下微信公众平台的开发吧~ 其实微信公众平台开发没有想象中的那么困难,因为注册了微信公众平台帐号登录之后在开发者模式里有详细的文档,个人感觉介绍还是比较详细的. 微信公众平台订阅号和服 ...