Game Development Reference
In-Depth Information
The target width and height are equal to the screen resolution for which the graphical assets
were designed; in Replica Island , the dimensions are 480×320 pixels. For the Nexus One, there
is a scaling factor of 1.66 on the x axis and a scaling factor of 1.5 on the y axis. Why are the
scaling factors on the two axes different?
This is due to the fact that two screen resolutions have different aspect ratios. If we simply
stretch a 480×320-pixel image to an 800×480-pixel image, the original image is stretched on the
x axis. For most games, this will be insignificant, so we can simply draw our graphical assets
for a specific target resolution and stretch them to the actual screen resolution while rendering
(remember the Bitmap.drawBitmap() method).
However, for some games, you might want to use a more complicated method. Figure 5-3
shows Replica Island scaled up from 480×320 to 800×480 pixels and overlaid with a faint image
of how it actually looks.
Figure 5-3. Replica Island stretched from 480×320 to 800×480 pixels, overlaid with a faint image of how it is rendered on
an 800×480-pixel display
Replica Island performs normal stretching on the y axis using the scaling factor we just
calculated (1.5), but instead of using the x-axis scaling factor (1.66), which would squish the
image, it uses the y-axis scaling factor. This trick allows all objects on the screen to keep their
aspect ratio. A 32×32-pixel sprite becomes 48×48 pixels instead of 53×48 pixels. However,
this also means that our coordinate system is no longer bounded between (0,0) and (479,319);
instead, it ranges from (0,0) to (533,319). This is why we see more of Replica Island on a Nexus
One than on an HTC Hero.
Note, however, that using this fancy method might be inappropriate for some games.
For example, if the world size depends on the screen aspect ratio, players with wider screens
could have an unfair advantage. This would be the case for a game like StarCraft 2 . Finally, if you
want the entire game to fit onto a single screen, like in Mr. Nom, it is better to use the
simpler stretching method; if we use the second version, there will be blank space left over
on wider screens.
 
Search WWH ::




Custom Search