I wanted to get some input from you guys on what method to use when converting logical positions and dimensions to their view counterparts and vice versa in a 2D game.
To give you some context, the game is a simple top down 2d game. The game is competitive and multiplayer. All game related positions and dimensions (x, y, widht, height etc) are in a logical cartesian space and when rendering it is scaled to view space. The other way around is also true, for example, when getting input from the mouse, the click position is converted from view to logical space.
Two psuedo code use cases might look like:
render( camera.to_view(entity.x), camera.to_view(entity.y), camera.to_view(entity.w), camera.to_view(entity.h) ); get_mouse_pos( camera.to_logical(mouse.x), camera.to_logical(mouse.y) );
So, I can think of two ways to do this.
1. Using a scale that depends on the level and screen width
scale.x = screenWidth / levelWidth; scale.y = screenHeight / levelHeight;
This will make it so that the same number of logical units will be shown no mather what resolution the screen is. The logical positions and dimensions will simply be scaled to match the screen resolution.
- gameplay will be the same on all screen resolutions (the same amount of logical units are always shown)
- might look wierd on a lot of resolutions because of scaling
2. Using a fixed scale
scale = 10;
This will make it so that (screenWidth / scale and screenHeight / scale) number of logical units will be shown. The logical positions and dimensions are always scaled the same; by [scale] amount.
- easier to make it look good, since scaling is always the same on all resolutions
- will affect gameplay, since players using a screen with larger resolutions will see more of the level
PS: I say "screen" but you can think of it as a viewport, in case the game is no in fullscreen, everything still applies.
PSS: "positions and dimensions" are really points and vectors.. lol
So, I would love to get some feedback on what you think will work the best, thanks in advance! / AS
Edited by AlanSmithee, 13 January 2014 - 09:50 AM.