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

标签 c# .net xna title

我想做的是制作一个像 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/

相关文章:

c# - 即使机器重新启动,如何永久保存动态按钮

c# - XNA 时序如何工作?

c# - 关于平台游戏 Actor /背景碰撞解决的意见

C# - System.Threading.Monitor 控制线程的优势

c# - 如何使用 NHibernate 连接多个 1 到多关系表

c# - 序列化包含字典成员的类

c# - Msmq .NET api MessageQueue.Send 不会在预期的地方抛出

c# - 使用 GPU 加速 BigInteger 计算

c# - 在每像素碰撞后控制玩家移动

c# - 将类转换为类库并实例化