c# – 动画标题(像Terraria的游戏标题)
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了c# – 动画标题(像Terraria的游戏标题),小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2421字,纯文字阅读大概需要4分钟。
内容图文
![c# – 动画标题(像Terraria的游戏标题)](/upload/InfoBanner/zyjiaocheng/803/f78c35f8913c4504ae123ef61573ca7b.jpg)
我想做的是让像Terraria这样的标题只是摇摆来回的一面而不是图形方面我知道它只是一个.png来回摇摆但是任何人都可以帮助我和其他阅读此内容的人知道怎么做吗?
所以我想要学习如何制作像Terraria中显示的标题一样的来回摇摆图像?
对于那些不知道Terraria是什么的人来说,这样的事情.
http://www.youtube.com/watch?v=3K8PMG42l3M
解决方法:
看起来徽标在不相等的时间间隔内旋转并改变其大小.
首先,您需要熟悉this method:
SpriteBatch.Draw Method (Texture2D, Vector2, Nullable, Color, Single, Vector2, Single, SpriteEffects, Single)
参数是:
Texture2D texture, // texture of your logo
Vector2 position, // where to draw
Nullable<Rectangle> sourceRectangle, // null
Color color, // Color.White
float rotation, // you will be changing this
Vector2 origin, // and this
float scale, // also this
SpriteEffects effects, // SpriteEffects.None
float layerDepth // 0
使用这些变量:
float rotation = 0,
rotationSpeed = 0.002f, // this is how much rotation will change each frame
maximumAngle = 0.1f,
minimumAngle = -0.1f,
rotationDirection = 1,
scale = 1f, // 1 means 100%, 0.95f = 95%
scaleChange = 0.005f, // this may seem not much, but it's enough
maxScale = 1.1f,
minScale = 0.9f,
scaleDirection = 1;
只需输入DrawLogo();在你的主Draw()方法中.
void DrawLogo()
{
// these two very similar pieces of code will control scale and rotation
if (rotationDirection > 0)
{
if (rotation < maximumAngle)
rotation += rotationSpeed;
else
rotationDirection = -rotationDirection;
}
else
if (rotation > minimumAngle)
rotation -= rotationSpeed;
else
rotationDirection = -rotationDirection;
if (scaleDirection > 0)
{
if (scale < maxScale)
scale += scaleChange;
else
scaleDirection = -scaleDirection;
}
else
if (scale > minScale)
scale -= scaleChange;
else
scaleDirection = -scaleDirection;
Texture2d t2d = logoTexture;
spriteBatch.Draw(t2d,
centerScreen, // change this to `new Vector2(123, 456)`
null, // null means draw entire texture
Color.White, // no tinting
rotation, // the rotation we calculate above
new Vector2(t2d.Width / 2, t2d.Height / 2),
// this sets rotation point to the center of the texture
scale, // the scale we calculate above
SpriteEffects.None, // you can mirror your texture with this
0); // I usually leave it zero :p
}
这是经过测试,效果很好:)
内容总结
以上是互联网集市为您收集整理的c# – 动画标题(像Terraria的游戏标题)全部内容,希望文章能够帮你解决c# – 动画标题(像Terraria的游戏标题)所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。