To clear up some possible confusion caused by my title, my game is meant to be pixelly. I currently achieve this by multiplying sprite sizes and locations by a constant called World.Scale (currently 8). This means every pixel is now 8x8 on screen, which is what I want.

However, I want an easier way to do game calculations without having to figure out where to fit World.Scale whenever I'm drawing or calculating something. Also, I'm currently having trouble with pixel-mismatching (see image).


To solve this, I thought about rendering everything in the game onto a render target, and then scale that render target up by World.Scale and draw it to the screen but I'm not sure how render targets work so I'm not sure about any possible performance implications of this.

Is it a good idea? Is there a better alternative?

  • \$\begingroup\$ It's not clear to me precisely what you consider to be "pixel mismatching" in the image. is it the fact that your icon pixels don't end up on the same grid as your background pixels? \$\endgroup\$
    – user1430
    Jun 23, 2016 at 19:53
  • \$\begingroup\$ @JoshPetrie Yes, that is exactly what I mean. That's why I want to render everything at 1:1 and then scale it all up to 1:8 at render time. \$\endgroup\$
    – Pyroglyph
    Jun 23, 2016 at 22:51

1 Answer 1


Note that you can supply the SpriteBatch.Begin with a matrix parameter. Use your ingame "virtual screen" dimensions to calculate the scale factor. This way you can draw your game in the native "virtual" resolution and have the matrix do the heavy lifting for you.

For example:

float xscale = (float)ScreenWidth / VirtualscreenWidth;
float yscale = (float)ScreenHeight / VirtualscreenHeight;
Matrix transformmatrix = Matrix.CreateScale(xscale, yscale,1.0f);

spriteBatch.Begin(,,,transformmatrix); //supply parameters as usual but add the matrix.

You can make this better by calculating the matrix while respecting the aspect ratio (use pillarbox or letterbox).

I believe monogame.extended has an implementation using this method (and other useful stuff!)

  • \$\begingroup\$ I had a look at MonoGame.Extended but there doesn't seem to be much in the way of documentation so I'll probably just stick to the matrix idea. I've not used matrices before, so this is kind of exciting for me :D \$\endgroup\$
    – Pyroglyph
    Jun 24, 2016 at 10:06
  • \$\begingroup\$ So the matrix scaling worked great for the alignment problem I was having, but now the rectangle objects i use for drawing my buttons are still in the top left corner. Is there a way of scaling those in a similar way? Perhaps also using matrices? \$\endgroup\$
    – Pyroglyph
    Jun 24, 2016 at 14:16
  • \$\begingroup\$ The point is that everything you want to draw to the screen uses the same transformation matrix. Your games' only concern is the 'virtual resolution' of the 1:1 game. Unless you want some UI elements being drawn at the screen native resolution. \$\endgroup\$
    – Felsir
    Jun 24, 2016 at 21:42
  • \$\begingroup\$ I found a useful answer somewhere else on GameDev.SE (no link right now) that said I should have something that translates the mouse's current coordinates to the virtual resolutions so the hotboxes never need to be modified (again making things easier to code in the long run) \$\endgroup\$
    – Pyroglyph
    Jun 24, 2016 at 21:50
  • \$\begingroup\$ Ah, you want the inverse of the matrix to translate mousecoords back to your coordinates. 'Matrix invmatrix = Matrix.Invert(transformmatrix); And then you can convert back your mouse like this: Vector2.Transform(mousecoords.ToVector2(), invmatrix); \$\endgroup\$
    – Felsir
    Jun 25, 2016 at 15:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .