简体   繁体   English

将XNA Texture2D旋转到另一个Texture2D中

[英]Rotating XNA Texture2D into another Texture2D

I know that Texture2D can be rotated during the Draw() process, but what I'm asking is a little different. 我知道在Draw()过程中可以旋转Texture2D,但我要问的是有点不同。 I need the rotated Texture2D before drawing it, and storing it into another Texture2D for further manipulation. 在绘制之前我需要旋转的Texture2D,并将其存储到另一个Texture2D中以便进一步操作。 Something along the lines of: 有点像:

   Texture2D rotated = getRotatedTexure(originalTexture);

However, I don't even know where to start. 但是,我甚至不知道从哪里开始。 Do I convert my texture to an Image and do my work form there? 我是否将纹理转换为图像并在那里处理我的工作表单? Any advice would be greatly appreciated. 任何建议将不胜感激。

The reasons for this are long and complicated, but essentially I am trying to build a rotational animation engine (AKA: "Skeletal Animation", "Bone Animation", or "Cutout Animation"). 造成这种情况的原因既冗长又复杂,但实际上我正在尝试构建旋转动画引擎(AKA:“骨骼动画”,“骨骼动画”或“剪掉动画”)。

试试这个: XNA旋转纹理2D

The thing you can do is to define a RenderTarget2D and draw in it the rotated texture. 你可以做的是定义一个RenderTarget2D并在其中绘制旋转的纹理。 Example: 例:

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

If you then want to draw on the screen the rotated texture you can do: 如果您想在屏幕上绘制rotated texture您可以执行以下操作:

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM