Reputation: 1724
When I shrink my large texture down, it doesn't shrink the image. It just cuts off the image starting from the bottom right and going up diagonally.
This is how I am drawing the sprite:
spriteBatch.Draw(Tiles[0].TileTexture, new Vector2(x * TileWidth, y * TileHeight), Color.White);
This is the base image I'm testing with.
This is what it looks like at 16,16
And 64,64
Upvotes: 0
Views: 51
Reputation:
If you use image 16x16 then cell size should be 16x16. But if you want draw 64x64 image in cell 16x16 you should scale image down to 16x16, but in this case there will be no difference between in 64x64 and 16x16 source images. Or make cells 64x64 pixels.
What about zoom you can use only integer scale, like 2x, 3x and so on. Not allow non-integer scale to avoid image distortion.
SpriteBatch.Draw has overloads. To scale image as you want you can use overload 1, 2 or 3 with destination rectangle as second parameter:
SpriteBatch.Draw(
tileTexture,
new Rectange(x * TileWidth, y * TileHeight, TileWidth, TileHeight),
Color.White);
Source image will be stratched to rectangle.
Or you can use on of two last overloads to scale image
SpriteBatch.Draw(
tileTexture,
new Vector2(x * TileWidth * scaleX, y * TileHeight * scaleY),
null,
Color.White,
0,
Vector2.Zero,
new Vector2(scaleX, scaleY),
SpriteEffects.None,
0);
Also, if you just need fill background with one same tile you can call spritebatch begin methos with any wrap SemplerState paramether (PointWrap better as for me) and draw tile once like this: SpriteBatch.Draw( tileTexture, new Rectange(0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height), Color.White);
Upvotes: 1