When I animate my object with a spritesheet texture after scaling the game from 1920 x 1080 to a 960 x 540 window, it doesn’t look right… Here’s what it looks like:
If you take a close look, you can see the messy stuff at the top animating(probably from the other frames?)
But here’s the thing, if I scale it up back to 1920x1080, it doesn’t do that. It’s perfect, here’s what THAT looks like:
Here’s my source code for the animation in the player class:
public class Player
{
Texture2D Texture;
Vector2 Position;
public int Rows { get; set; }
public int Columns { get; set; }
public int currentFrame = 0;
float interval;
public int Width
{
get
{
return Texture.Width / Columns;
}
}
public int Height
{
get
{
return Texture.Height / Rows;
}
}
public void Update(GameTime gameTime)
{
if (interval < 0.1f)
{
interval += timer;
}
if (interval >= 0.1f)
{
interval = 0f;
currentFrame++;
}
if (currentFrame > 11)
{
currentFrame = 0;
}
}
public void Draw(SpriteBatch spriteBatch)
{
int width = Texture.Width / Columns;
int height = Texture.Height / Rows;
int row = (int)((float)currentFrame / (float)Columns);
int column = currentFrame % Columns;
Rectangle sourceRectangle = new Rectangle(width * column, height * row, width, height);
Rectangle destinationRectangle = new Rectangle((int)Position.X, (int)Position.Y, Width, Height);
spriteBatch.Draw(Texture, destinationRectangle, sourceRectangle, color, 0f, Vector2.Zero, SpriteEffects.None, layer);
}
here’s the scaling stuff in the main Game1.cs class:
public class Game1 : Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
Vector2 virtualScreen = new Vector2(1920, 1080);
Vector3 scaleFactor;
Matrix Scale;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
this.Window.Title = "VOID";
graphics.PreferredBackBufferWidth = 960;
graphics.PreferredBackBufferHeight = 540;
}
protected override void Update(GameTime gameTime)
{
float widthScale = GraphicsDevice.PresentationParameters.BackBufferWidth / virtualScreen.X;
float heightScale = GraphicsDevice.PresentationParameters.BackBufferHeight / virtualScreen.Y;
scaleFactor = new Vector3(widthScale, heightScale, 1);
Scale = Matrix.CreateScale(scaleFactor);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(bgColor);
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, null, null, null, null, Scale);
player.Draw(spriteBatch);
spriteBatch.End();
base.Draw(gameTime);
}
Thanks for your help, I appreciate your time.