Predator14567

     
Hi, I was wondering how I could scale textures, as the textures are too big than what I need for certain parts of the game, I think its in the SpriteBatch.draw method, but its hard to manuever through all of their intellisense arguments....
For XNA


Re: Game Technologies: Graphics Scaling Sprites?(XNA)

ProfEclipse

Look at the SpriteBatch.Draw overloads that accept a destination Rectangle. Draw will scale the image down to the size of the destination rectangle.





Re: Game Technologies: Graphics Scaling Sprites?(XNA)

Robert Hernandez

Would anyone be able to explain how I should be using the SpriteBatch.Draw overload functions to properly scale textures I'm a little confused about how to pass the parameters using the overloads and I think it may have to do with the way I've implemented my sprites.

For the code below I am applying a texture that measures 100pix by 100pix to an object that is instantiated at 50pix by 50pix as defined by its class. I would like to scale the texture so it fits the 50x50 object. I believe the scaling is supposed to occur in the LoadGraphicsContent method where I place the call to the Spritebatch.Draw method but I have been unsuccessful in figuring out the proper way to do so.

public Engine()
{
this.graphics = new GraphicsDeviceManager(this);
this.content = new ContentManager(this.Services);
this.Jimmie = new Image();
}

protected override void Initialize()
{

this.Jimmie.InitializeSize();
base.Initialize();

}

protected override void LoadGraphicsContent(bool loadAllContent)
{
if (loadAllContent)
{

this.myJimmie = this.content.Load<Texture2D>(@"resources\textures\jimmiemac");

this.spriteBatch = new SpriteBatch(this.graphics.GraphicsDevice);

this.Jimmie.LoadGraphicsContent(this.spriteBatch, this.myJimmie);
}
}

protected override void UnloadGraphicsContent(bool unloadAllContent)
{
if (unloadAllContent)
{
this.content.Unload();
}
}

protected override void Update(GameTime gameTime)
{
base.Update(gameTime);

}

protected override void Draw(GameTime gameTime)
{
this.graphics.GraphicsDevice.Clear(Color.Black);

this.spriteBatch.Begin(SpriteBlendMode.None);
this.Jimmie.Draw(gameTime);
this.spriteBatch.End();

base.Draw(gameTime);
}




Re: Game Technologies: Graphics Scaling Sprites?(XNA)

ProfEclipse

If you specify a source rectangle of 100x100 (your entire texture) and a destination rectangle of 50x50 (your sprite size) in your Draw call, the texture will automatically be scaled down to 50x50.