I am new to game development and I wanted to ask a question.

I am reading the simple game example from here.

1) I want to ask why we define bucket.x = 800 / 2 - 48 / 2 ? How is that? Why not just set bucket.x=400 ( at the middle position).


camera.setToOrtho(false, 800, 480);
bucket = new Rectangle();
   bucket.x = 800 / 2 - 48 / 2;
   bucket.y = 20;
   bucket.width = 48;
   bucket.height = 48;

2) The bucket width and height are seet 1/10 of our screen size.Ok. But what about the real dimensions of bucket object?I mean , the bucket what size must be?32x32 pix?48X48 pix?How we handle that?

3) Also, I am a bit confused about x and y dimensions. x refers to width and y to height as we see the cell phone in portrait mode? So , if we are in landscape mode , y is "x"?


  • \$\begingroup\$ Sounds like you want a discussion about it, you should ask in chat since you have the rep. \$\endgroup\$
    – MichaelHouse
    May 31 '13 at 14:19
  1. If you set bucket.x as 400 you will draw the left edge of the bucket at 400 which will make it displaced to the right. You need to draw the center of the bucket at 400 to effectively center it, hence you subtract its size divided by 2.

  2. There are multiple ways to handle this. In my small project I'm using a fixed Orthographic. You set the camera width to 480 pixels. If you display that camera on a different screen size it will still be 480 stretched to the new size, and the bucket will be 48 pixels stretched to fit. The best way to work in my (little) experience is to choose a resolution and make your assets based on that resolution and let the engine to the scale job. There is multi-resolution options for optimal display but that requries multiple size assets and it is better start simple.

  3. X will always be the horizontal coordinate and Y the vertical one. Just consider you changed resolutions, for example, from 640x480 to 480,640.

  • \$\begingroup\$ 1) So , using 800 / 2 - 48 / 2 . The "48/2" is for taking the center of the image?. 3) Yes, but if I change layouts (portrait and landscape) x and y interchange. Thanks! \$\endgroup\$
    – George
    May 31 '13 at 12:06
  • \$\begingroup\$ As I said, X will still be X, width will still be width, consider you change the resolutions, not the coordinates. \$\endgroup\$
    – petervaz
    May 31 '13 at 12:09
  • \$\begingroup\$ :It says "bucket.y = 20; // bottom left corner of the bucket is 20 pixels above the bottom screen edge".If I change the layouts y changes.I am sorry I can't think it. \$\endgroup\$
    – George
    May 31 '13 at 12:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.