gpt4 book ai didi

c# - 动画标题(如泰拉瑞亚的游戏标题)

转载 作者:太空狗 更新时间:2023-10-30 00:42:43 26 4
gpt4 key购买 nike

我想做的是制作一个像 Terraria 这样的标题,只是它的来回摇摆而不是图形方面我知道它只是一个来回摇摆的 .png 但任何人都可以帮助我和其他阅读这篇文章的人以及如何知道该怎么做?

所以我想学习如何制作像 Terraria 中显示的标题一样来回摇摆的图像?

对于那些不知道泰拉瑞亚是什么的人来说,这是类似的东西。

http://www.youtube.com/watch?v=3K8PMG42l3M

最佳答案

看起来 Logo 在不相等的时间间隔内旋转并改变其大小。

首先,您需要熟悉 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# - 动画标题(如泰拉瑞亚的游戏标题),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13986042/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com