I'm making a game for the Android. It's just a simple puzzle/zombie game with no particularly remarkable features. I'm pretty much just in it for the experience.
The game is (more or less) density independent. It operates perfectly in a 3:4 aspect ratio, but in other ratios, the Rects for the tiles are usually off by one pixel. I know why this occurs, but with so little experience with the Android API, I require some help in formulating a fix.
I'd prefer not to just decrease the size of the bounding boxes by 1 pixel. I don't want to break out of the tile grid.
The issue occurs when calculating the size of the tiles, and it's probably a rounding error.
To find the dimensions of the screen, I have a simple Screen class with static fields for the height and width
private static DisplayMetrics screen = Malld.getContext().getResources().getDisplayMetrics(); public static final int width = screen.widthPixels; public static final int height = screen.heightPixels;
Using this information, I set the size of the tile using (int)(Screen.width / 7.5)) for the width, and (int)(Screen.height / 10)) for the height.
I'm getting throughput errors (collisions where there shouldn't be collisions) when I run the game on a device with a funny aspect ratio.
3:4 aspect ratio(left), long screen(right)
The grid appears to be aligned, but my bounding boxes are colliding when they shouldn't be. Should I be flooring all values to avoid a possible rounding error?
EDIT: Don't worry about the image artifacts, or the fact that I suck at pixel art. Right now I'm just worried about the misaligned tile grid.
This post has been edited by Gungnir: 19 April 2013 - 05:48 PM