Question

i'm a newbie in XNA just in case. What i try to do is load a texture in a different size from his original, or at least have the possibility to change his size after. I see in some places that i can use:

Texture2D.FromStream(GraphicsDevice graphicsDevice, Stream stream, 
                 int width, int height, bool zoom)

But i also read that loading textures in this way is ignoring the ContentManager, and that i'm making the job for the garbage collector more difficult.

What is the Correct way to load an image in any size, using the ContentManager ? If that isn't possible can i change his size proportionally, like using a zoom?

Context: I'm creating a board of n x n peaces. When n is too big i need that automatically the peaces becomes more smaller.

Was it helpful?

Solution

To load the texture:

Texture2D tex = Content.Load<Texture2D>("somefile");

To resize it use one of the SpriteBatch overloads that takes "scale" http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.spritebatch.draw.aspx

float scale = .5f; //50% smaller
SpriteBatch.Draw(tex, position, source, Color.White, rotation, scale, SpriteEffects.None, 0f);

If you are new to XNA, I suggest you read this short tutorial, and also check out Education Catalog at create.msdn.com

OTHER TIPS

Texture2D texture;
protected override void LoadContent()
        {
...
         texture = Content.Load<Texture2D>("Tank");
...
        }
protected override void Draw(GameTime gameTime)
        {
...
         Rectangle destinationRectangle = new Rectangle(100, 100, 30, 10);
         spriteBatch.Draw(texture, destinationRectangle, Color.White);
...
         spriteBatch.End();
         base.Draw(gameTime);
        }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top