Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a normal game window which is 640*480, and everything is fine, but when I try to maximize the window, the objects translate to different positions on the screen, for example If I have a circle which is drawn at the center in the normal window, when I try to maximize it, it shifts away from the center of the screen. How do I adjust it so it draws at the center in both normal window and maximized window ?

share|improve this question
it sounds like more of the screen is being drawn, maybe you just need to change the focus point of your camera? – Benjamin Danger Johnson Oct 23 '12 at 22:14
up vote 3 down vote accepted

Is this is a 2D game, you need to position your objects based on ratios or percentages.

For example instead of putting your object at (320, 240) to center it. Put it at (.5f*ScreenWidth, .5f*ScreenHeight). Make sure you update any bufferer vertices when resizing so that their positions are updated.

If it's a 3D game, your camera class should expand the view port from the center out. Meaning, keep the camera in the same position, with the same target vector.

share|improve this answer
In addition, it may be worthwhile to create some shortcut functions that draw things at a position based on the resolution. You might set it up so draw(.5, .5) draws at the center of the screen, or you might code with a specific resolution in mind and have the function do the adjusting for you (i.e. draw(320, 240)). This is probably easier in the context of games. – tesselode Oct 24 '12 at 1:28

This may not be the most efficient method, but it's certainly easy. If you can make canvases/surfaces/framebuffers/whatever you call them, then you can just code the game for a specific resolution (may as well stick with 640x480), draw everything gameplay-related to the canvas, and then draw the canvas scaled based on the window width and/or height.

For a game that is usually 640x480:

x_scale = 480 / window_height
y_scale = 480 / window_height
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.