惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
Stack Overflow Blog
Stack Overflow Blog
Hugging Face - Blog
Hugging Face - Blog
博客园_首页
T
The Blog of Author Tim Ferriss
博客园 - 叶小钗
N
Netflix TechBlog - Medium
腾讯CDC
C
Check Point Blog
P
Proofpoint News Feed
Engineering at Meta
Engineering at Meta
GbyAI
GbyAI
S
SegmentFault 最新的问题
F
Fortinet All Blogs
美团技术团队
U
Unit 42
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 司徒正美
F
Full Disclosure
Recorded Future
Recorded Future
D
DataBreaches.Net
博客园 - 【当耐特】
Martin Fowler
Martin Fowler
J
Java Code Geeks
I
InfoQ
Y
Y Combinator Blog
A
About on SuperTechFans
AI
AI
爱范儿
爱范儿
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Forbes - Security
Forbes - Security
W
WeLiveSecurity
M
MIT News - Artificial intelligence
雷峰网
雷峰网
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Simon Willison's Weblog
Simon Willison's Weblog
Schneier on Security
Schneier on Security
The GitHub Blog
The GitHub Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
aimingoo的专栏
aimingoo的专栏
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
G
GRAHAM CLULEY
Know Your Adversary
Know Your Adversary
Latest news
Latest news
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
D
Docker
Recent Commits to openclaw:main
Recent Commits to openclaw:main
量子位
V2EX - 技术
V2EX - 技术
Project Zero
Project Zero

博客园 - 张剑

WebMatrix&Razor建站系列之WebMatrix介绍 Windows Phone 7 XNA开发之关于游戏组件 Windows Phone 7 XNA开发之关于图形的配置 EntityFramework外健的读写 vs2010中添加项目中找不到EntityFramework实体框架解决办法 使用MSDN学习ASP.NET的工作流程 《XNA游戏开发》在战机游戏中使用Decorator模式 不被重视的基础,简单高效地使用ADO.net连接对象 微软2011 GCR MVP Open Day 之旅! ASP.NET4.5与VisualStudio11预览 程序员杂记系列文章,30岁之前的回忆。 程序员杂记:带面具的生活! MVC中在路由表routes集合中添加Route实例的一些问题。 Windows Phone 7之HelloWorld! MVC3+Entity Framework 实现投票系统(三) MVC3+Entity Framework 实现投票系统(二) MVC3+Entity Framework 实现投票系统(一) 关于Windows Phone 7开发工具离线安装包 程序员杂记:我们的爱情故事
Windows Phone 7、XNA的旋转的背景
张剑 · 2011-12-26 · via 博客园 - 张剑

2011-12-26 17:58  张剑  阅读(870)  评论()    收藏  举报

在游戏表现的过程中需要一些比较酷的动作,我们需要通过图型与XNA中的一些代码来实现,比如我们要说到的一个360度转动的圆。

在手机上的效果如下:

当然在这里我们看不到转动的效果,下边提供的有源码,大家可以下载运行测试一下。

操作步骤如下:

1.创建WP7XNA项目。

2.在Game1类中,添加如下代码:

        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        Texture2D _Aluren;//纹理
        Rectangle _AlurenRectangle;//位置大小
        Rectangle _SrAlurenRectangle;//源矩形
        int i = 0; //旋转角度
        Vector2 _Origin;//起点

其中加了注释的是需要我们自己创建的字段。

3.在Initialize()方法或者构造方法中添加如下代码:

            _AlurenRectangle = new Rectangle(220, 220, 600, 600);
            _SrAlurenRectangle = new Rectangle(0, 0, 800, 800);
            _Origin = new Vector2(400, 400);

这样或以初始化圆形的位置、旋转的源矩形及起点。

4.将Aluren.png图片放到WindowsPhoneGameContent项目中。

5.在LoadContent()方法中添加如下代码:

  _Aluren = Content.Load<Texture2D>("Aluren");

在这里完成图片纹理的加载。

6.在Update(GameTime gameTime)方法中添加:

            if (i >= 360)
                i = 0;
            i++;

在每次刷新时,绘制的角度+1,直到360度后重新开始,当然这里的度数也可以是其他,比如90,180等。

7.最后在Draw(GameTime gameTime)方法中完成绘制功能:

            spriteBatch.Begin();
            spriteBatch.Draw(_Aluren, _AlurenRectangle, _SrAlurenRectangle, Color.White, i, _Origin, SpriteEffects.FlipHorizontally, 0);
            spriteBatch.End();

整个程序完成后,运行即可看到效果。

图片文件:http://jianle.blog.51cto.com/attachment/201112/429692_1324893909.png

源码:http://jianle.blog.51cto.com/attachment/201112/429692_1324894092.zip

注意:下载完成后,需要将图片文件放入到源码中才能使用!