2 Replies - 534 Views - Last Post: 19 April 2013 - 05:47 PM

#1 Gungnir  Icon User is offline

  • Your Imaginary Friend

Reputation: 152
  • View blog
  • Posts: 527
  • Joined: 21-May 11

Difficulty Calculating 'Tile Size' in Different Aspect Ratios

Posted 19 April 2013 - 04:38 PM

FIXED


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.

Posted Image Posted Image
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


Is This A Good Question/Topic? 0
  • +

Replies To: Difficulty Calculating 'Tile Size' in Different Aspect Ratios

#2 Gungnir  Icon User is offline

  • Your Imaginary Friend

Reputation: 152
  • View blog
  • Posts: 527
  • Joined: 21-May 11

Re: Difficulty Calculating 'Tile Size' in Different Aspect Ratios

Posted 19 April 2013 - 05:02 PM

Nope. I debugged both methods with LogCat and they both return the same tile size:
04-19 23:59:51.057: D/(860): TILE >> (64 x 80)
04-19 23:59:51.057: D/(860): TILE (floor) >> (64 x 80)



I have a few more ideas, but for now it's back to the drawing board.
Was This Post Helpful? 0
  • +
  • -

#3 Gungnir  Icon User is offline

  • Your Imaginary Friend

Reputation: 152
  • View blog
  • Posts: 527
  • Joined: 21-May 11

Re: Difficulty Calculating 'Tile Size' in Different Aspect Ratios

Posted 19 April 2013 - 05:47 PM

Nevermind, it wasn't a tile issue at all. My movement speed wasn't density independent, and as a result my hero would never reach his destination. He kept turning around to get to a coordinate that he could never arrive at. Now the speed of the player is based on the width of the tile, and the issue is fixed.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1