user2020389
user2020389

Reputation: 1

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. I need the rotated Texture2D before drawing it, and storing it into another Texture2D for further manipulation. 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 (A.K.A: "Skeletal Animation", "Bone Animation", or "Cutout Animation").

Upvotes: 0

Views: 195

Answers (2)

Francesco Bonizzi
Francesco Bonizzi

Reputation: 5302

The thing you can do is to define a RenderTarget2D and draw in it the rotated texture. 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:

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

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

Upvotes: 0

Memoizer
Memoizer

Reputation: 2279

Try this: XNA Rotate Texture 2D

Upvotes: 2

Related Questions