I have a lot of objects on the screen and would like at different resolutions, object's positions rendered correctly on the screen irrespective of the resolution. Is it correct to multiply the position by aspect ratio ?
Instead of noting your objects position with a 2d vector(absolute, in pixels) you should use a mix of two 2d vectors (relative, in percentage component and offset component)
The percentage component are two float variables with a value in the range 0.0 ~ 1.0. It specifies how much away from screen origin you are.
This explains it:
This way, you can do it:
To achieve this, you should use something like this to calculate the absolute coordinates given the relative:
Should work fine. Lots of GUI systems use this approach.
As @milkplus stated, anchoring is a good way to do it too, and if I'm not mistaken it's also how Windows do it on it's UI designers.
Just in case, you can simulate it with Relative positioning too. You just have to specify the edge you want to use (
Instead of scaling like @Gustavo suggests, you could also just anchor your screen objects to the edges. That's how UI designers often work. A negative screen coodinate is taken to be anchored to the right or bottom.
For development, you could scale width and height for resolution. I would recommend uniform scaling instead of using the aspect ratio. Take the minimum of (designWidth/screenWidth) and (designHeight/screenHeight) to scale your UI elements. I normally pick ipad2 resolution (1024,768) as my design resolution.
For production, I would recommend having different sets of bitmaps rather than scaling.
If you originally setup your GUI while considering a system with resolution