0
votes

Imagine, I have a picture (Texture2D in XNA) scalled 256x256, but sometimes I want to use it with a size of 64x64 in the application.

I learned on regular Windows Forms or WPF applications, when I have to resize an image, I should store it in a field so that I have to do the resizing only once. It would massively slow down the performance when resizing in the game loop over and over again.

Do I have to that in XNA too? I didn't find anything about it. I can resize the texture when drawing with the spritebatch but that would be the same as just explained. I would resize the texture every frame and not only once in the field. I don't even know how to resize a texture2d without spritebatch in XNA.

2

2 Answers

0
votes

There is no reason to create a resized copy of the original texture. Just draw it at whatever size you want. Drawing a texture at a different size than the original image is essentially free on modern graphics hardware.

0
votes

With modern hardware, you rarely need to manually resize textures, the hardware does all that automatically. However, you must make sure you are using mipmapping, else the result will be very aliased.

If mipmapping is enabled on your current texture, it will be resized when it is loaded. Just make sure trilinear filtering render state is enabled and draw whatever size you need and it will automatically use a mix of the best resized textures.