Reputation: 174
I'm porting my game from WP7 to Android. My game is a kind of "Color Lines" game. There is a board with cells (it is a part of static background image), where can be placed balls. On WP7 everything is fine with coordinates: all WP7 devices has resolution of 800*480, and I can easily define which cell is user has tapped.
But there is some problem with android: on different screens I face different resolution. My game board has some graphical borders and I don't know their sizes on every android screen.
I don't know HOW to connect coordinates from getTouch event to the touched cell on the board(as I said above, it is a part of static background image of resolution 800*480).
Also, I don't know how to find a coordinates of center of the certain cell, where I want to place the ball.
Upvotes: 0
Views: 323
Reputation: 168
Scale the coordinates from the event to your image.
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics( metrics );
float x = 800 / metrics.widthPixel * event.getX();
float y = 480 / metrics.heightPixel * event.getY();
Upvotes: 2