4
\$\begingroup\$

This question is very closely related to a previous question of mine:

Scaling a game view with letterboxes?

My game runs at 480x800 right now but when the screen is smaller or bigger than that I want it to scale up/down the image while maintaining the aspect ratio to fit it as best as it can and then put black letterboxes on the top/bottom or left/right to fill in the left over space if it is of a different aspect ratio. The newly scaled game screen should be centered in the middle of the screen.

I don't know how to go about doing this at all since I want the playfield to be 480x800 because the touch controls use the X and Y coordinates of where the player touches the screen. So I have to figure out how to make it so if the display is centered then the (0,0) coordinate doesnt start in the middle of the letter box but in the top left corner of the playfield where it should be. Also I need to figure out how to make it so when the game is scaled up or down the touch screen controls still work relevant to the new position and scale of the scaled game screen.

I don't know which would be easier, having the game image rendered then scaled up or make it so the gameplay remains the same with object and item positioning but renders a higher resolution image and then have higher resolution image resources rendered on big screens and smaller ones on smaller screens so they're pre-scaled instead of scaled by the hardware or software.

I'm not sure what the best practice is or how to go about doing either method. Please help me out!

\$\endgroup\$

1 Answer 1

8
\$\begingroup\$

Usually, when you create a game for multiple displays, you create your game logic with a unit system independant from your display size.

For example, to keep your aspect ratio you can have your game using a 6x10 units, and use the same scale for all you element. Then when moving a game object you always use the same unit system, independant from your display.

Then you have to make a bridge between the display and the game, both in the rendering system (convert game unit to pixels, according to screen size) and in the input system (convert the input in pixels to position in game unit).

Once you've done this, you can focus on your game logic, without having to touch the input and rendering to adapt to different scale.

\$\endgroup\$
7
  • 1
    \$\begingroup\$ Very true. Using exact pixel values is NOT what you want to do probably more so with Android than anything else. \$\endgroup\$
    – Amplify91
    Commented Jul 21, 2011 at 20:15
  • \$\begingroup\$ I'm not quite sure I understand, and what is a 6x10 units? \$\endgroup\$
    – Kyle V.
    Commented Jul 22, 2011 at 5:28
  • \$\begingroup\$ The idea is that you use a virtual unit in your game independant from your screen size. For example, in a game of ping pong, you'll use a world size of 3 x 5 meters, for a tower defense, a world size of 60 x 100 meters. So here 6x10 was an example, just use a unit that is not in pixel but in meters, or inches, or anything according to your gameplay. Then create the methods in your rendering and input to convert meters to pixel and pixels to meters \$\endgroup\$
    – XGouchet
    Commented Jul 22, 2011 at 8:38
  • \$\begingroup\$ So for example the pong game would use units which are 3x5 squares on a 2d plane? Or am I misunderstanding? \$\endgroup\$
    – Kyle V.
    Commented Jul 25, 2011 at 19:04
  • 1
    \$\begingroup\$ Imagine a game like mario. The character will be 1.6 meters tall, and on screen you will see around 15 meters from left to right. Now for a 480x320 screen you'll have 32 pixels per meter. On larger screens it'll be more pixels per meters. So when rendering or getting user inputs you need to convert from pixels to meters \$\endgroup\$
    – XGouchet
    Commented Jul 27, 2011 at 4:49

You must log in to answer this question.

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