使用 Pinup,PinupManager 在 XNA 中创建贴图(十七)
平方已经开发了一些 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 中创建贴图(十七)的更多相关文章
- 使用 NPC,NPCManager 在 XNA 中创建 NPC
使用 NPC,NPCManager 在 XNA 中创建 NPC 平方已经开发了一些 Windows Phone 上的一些游戏,算不上什么技术大牛.在这里分享一下经验,仅为了和各位朋友交流经验.平方会逐 ...
- 使用 Region,RegionManager 在 XNA 中创建特殊区域(十八)
平方已经开发了一些 Windows Phone 上的一些游戏,算不上什么技术大牛.在这里分享一下经验,仅为了和各位朋友交流经验.平方会逐步将自己编写的类上传到托管项目中,没有什么好名字,就叫 WPXN ...
- 使用 NPC,NPCManager 在 XNA 中创建 NPC(十九)
平方已经开发了一些 Windows Phone 上的一些游戏,算不上什么技术大牛.在这里分享一下经验,仅为了和各位朋友交流经验.平方会逐步将自己编写的类上传到托管项目中,没有什么好名字,就叫 WPXN ...
- 使用 Item,ItemManager 在 XNA 中创建物品和道具(十六)
平方已经开发了一些 Windows Phone 上的一些游戏,算不上什么技术大牛.在这里分享一下经验,仅为了和各位朋友交流经验.平方会逐步将自己编写的类上传到托管项目中,没有什么好名字,就叫 WPXN ...
- 使用 Bullet,BulletManager 在 XNA 中创建子弹攻击目标(十五)
平方已经开发了一些 Windows Phone 上的一些游戏,算不上什么技术大牛.在这里分享一下经验,仅为了和各位朋友交流经验.平方会逐步将自己编写的类上传到托管项目中,没有什么好名字,就叫 WPXN ...
- 使用 Spirit 类在 XNA 中创建游戏中的基本单位精灵(十三)
平方已经开发了一些 Windows Phone 上的一些游戏,算不上什么技术大牛.在这里分享一下经验,仅为了和各位朋友交流经验.平方会逐步将自己编写的类上传到托管项目中,没有什么好名字,就叫 WPXN ...
- 使用 Button 类在 XNA 中创建图形按钮(九)
平方已经开发了一些 Windows Phone 上的一些游戏,算不上什么技术大牛.在这里分享一下经验,仅为了和各位朋友交流经验.平方会逐步将自己编写的类上传到托管项目中,没有什么好名字,就叫 WPXN ...
- 使用 Scene 类在 XNA 中创建不同的场景(八)
平方已经开发了一些 Windows Phone 上的一些游戏,算不上什么技术大牛.在这里分享一下经验,仅为了和各位朋友交流经验.平方会逐步将自己编写的类上传到托管项目中,没有什么好名字,就叫 WPXN ...
- 使用 CommandScene 类在 XNA 中创建命令场景(十二)
平方已经开发了一些 Windows Phone 上的一些游戏,算不上什么技术大牛.在这里分享一下经验,仅为了和各位朋友交流经验.平方会逐步将自己编写的类上传到托管项目中,没有什么好名字,就叫 WPXN ...
随机推荐
- Android Broadcast Receive
Broadcast Receive 广播接收(Broadcast Receive)为android的四大组件之一.主要用于监听广播消息,并做出响应.与应用程序中监听事件相比而言,该监听事件为全局监听. ...
- Eucalyptus学习汇总
Elastic Utility Computing Architecture for Linking Your Programs To Useful Systems (Eucalyptus) 是一种开 ...
- tf warning等级
from:http://blog.csdn.net/tsinghuahui/article/details/72938764 tf讨厌的warning 2017-08-03 10:02:52.0990 ...
- 数据库SQL优化大总结之 百万级数据库优化方案2
网上关于SQL优化的教程很多,但是比较杂乱.近日有空整理了一下,写出来跟大家分享一下,其中有错误和不足的地方,还请大家纠正补充. 这篇文章我花费了大量的时间查找资料.修改.排版,希望大家阅读之后, ...
- Visual Studio 2015 终于还是装上了
win8.1系统 vs2015.preview_ult_CHT.iso 大小4.46G, http://download.microsoft.com/download/9/9/1/99133C05-3 ...
- maven-整合到eclips
1.把maven的识别文件放到maven的安装路径下 2.在eclips中的properties中找到maven,勾选下载文档和下载源码的复选框以下载源码 3.创建maven项目 4.右键pom.xm ...
- pat甲级1016
1016 Phone Bills (25)(25 分) A long-distance telephone company charges its customers by the following ...
- Load事件中控件Focus()无效解决办法
原因:Load窗体时,窗体未显示 解决:1.Focus()之前添加this.Show(); 2.在Shown事件中添加Focus()
- PAT 乙级 1078 / 1084
题目 PAT 乙级 1078 PAT 乙级 1084 题解 1078和1084这两道题放在一块写,主要是因为这两道题的解法和做题思路非常相似:之前我做这一类题没有一个固定的套路,想到哪写到哪,在某种程 ...
- python 基础 for else
for one in many_list: if "k" in one: print "在里面" break else: print "没有在里面&q ...