So I made a scaling system for different resolutions, and I got very weird results.
I have an old "scaling" system where you can choose which scaleSize you want (for testing with the old 800 x 450 resolution) and you can choose between 1 and 2. I made a new scaling system after this that makes a scale with a matrix.
(old scaling system with scaleSize is just for making the textures/collision boxes bigger/smaller, not resolution dependent)
int currentWidth;
int currentHeight;
int preferredWidth;
int preferredHeight;
float scaleWidth;
float scaleHeight;
public Matrix scale;
GameWindow Window;
ContentManager Content;
GraphicsDeviceManager Graphics;
GraphicsDevice GraphicsDevice;
public ScreenSize(GraphicsDevice graphicsDevice, GraphicsDeviceManager graphics, ContentManager content, GameWindow window)
{
Window = window;
Content = content;
Graphics = graphics;
GraphicsDevice = graphicsDevice;
LoadContent();
}
public void LoadContent()
{
Graphics.PreferredBackBufferWidth = 1920;
Graphics.PreferredBackBufferHeight = 1080;
currentWidth = GraphicsDevice.Viewport.Width;
currentHeight = GraphicsDevice.Viewport.Height;
preferredWidth = 800;
preferredHeight = 450;
scaleWidth = currentWidth / preferredWidth;
scaleHeight = currentHeight / preferredHeight;
scale = Matrix.CreateScale(scaleWidth, scaleHeight, 1.0f);
this.Graphics.IsFullScreen = false;
Graphics.ApplyChanges();
}
I add the scale to my spriteBatch.Begin() and the textures are scaled. It works fine when the scaleSize is 2 but not when the scaleSize is 1.
The ScaleSize scales the collision box and the textures (not with the resolution, but just when you need (for example) a texture that's 2x bigger, then you use the scaleSize of 2. See an example below.
public virtual void Draw(GameTime gameTime, SpriteBatch spriteBatch, Color color, float scaleSize)
{
spriteBatch.Draw(textureImage, position, new Rectangle(
(currentFrame.X * frameSize.X),
(currentFrame.Y * frameSize.Y),
frameSize.X, frameSize.Y),
color, 0, Vector2.Zero, scaleSize, SpriteEffects.None, depth);
}
But the problem is that, when I use the scaleSize of 1, then the pixels in-game are not the same size (for resolutions that are not the default resolution (800 x 450)). But they are when scaleSize is 2. In my first code block I use the resolution 1920 x 1080. When the scaleSize is 2, then it looks good. When the scaleSize is 1, then it looks bad (in fullscreen it looks good for some reason).
example: (left is good, right is wrong)
I ask this question because I want the textures in-game smaller. (scaleSize = 1)
EDIT: scaleSize 2 doesn't look good on some resolutions (like 1440 x 900). Do I need another preferredWidth and preferredHeight?
summary: Everything looks/works fine with scaleSize 2, but doesn't with 1.
-> edit: scaling doesn't work well.


