0

I'm working on this 2D game for android where you have to shoot some enemies. Let's say I want to place a bitmap in the coordinates X=250 and Y=250. In my simulator that is exactly the middle of the screen, but in other devices is not. How can I set it so that the positions of my bitmaps are consistent with every device?

I've tried the the method: "canvas.getWidth()" but it only works inside the canvas method.

I hope you understand. Thank you.

Gonzalo
  • 29
  • 5

1 Answers1

0

You could use something like this in your Activity:

Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int center_x = size.x/2;
int center_y = size.y/2;

More on getting screen dimensions here: Get screen dimensions in pixels

Community
  • 1
  • 1
Dave S
  • 3,378
  • 1
  • 20
  • 34