【问题标题】:Rotating XNA Texture2D into another Texture2D将 XNA Texture2D 旋转到另一个 Texture2D
【发布时间】:2013-01-12 14:36:51
【问题描述】:

我知道 Texture2D 可以在 Draw() 过程中旋转,但我要问的有点不同。在绘制它之前我需要旋转的 Texture2D,并将其存储到另一个 Texture2D 中以供进一步操作。大致如下:

   Texture2D rotated = getRotatedTexure(originalTexture);

但是,我什至不知道从哪里开始。我是否将我的纹理转换为图像并在那里完成我的工作?任何建议将不胜感激。

原因很长而且很复杂,但本质上我是在尝试构建一个旋转动画引擎(A.K.A:“骨骼动画”、“骨骼动画”或“剪切动画”)。

【问题讨论】:

  • 你可以使用GetData和SetData。

标签: c# image xna rotation


【解决方案1】:

您可以做的是定义一个 RenderTarget2D 并在其中绘制旋转的纹理。 示例:

RenderTarget2D rotated_texture = new RenderTarget2D(GraphicsDevice, texture_width, texture_height);

GraphicsDevice.SetRenderTarget(rotated_texture);

spriteBatch.Begin();
//Draw the texture with rotation
spriteBatch.End();

GraphicsDevice.SetRenderTarget(null); //Reset to screen drawing

如果您想在屏幕上绘制rotated texture,您可以这样做:

//GraphicsDevice.SetRenderTarget(null); //Considering this done

spriteBatch.Begin();
spriteBatch.Draw(rotated_texture, vector_position, Color.White);
spriteBatch.End();

【讨论】:

    【解决方案2】:

    试试这个:XNA Rotate Texture 2D

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-04
      相关资源
      最近更新 更多