1
\$\begingroup\$

I cant work out how to use the rectangle bounds in libgdx I am currently using the superJumper example and have 2 or 3 examples with that are:

<!--this is the pause button in the top right corner-->
pause Bounds = new Rectangle(320 - 64, 480 - 64, 64, 64);

<!--this is a rectangle resume button in the middle of the
page in the menu that comes up when the pause button is pressed.-->
resume Bounds = new Rectangle(160 - 96, 240, 192, 36);

Basically my question is aimed at the 360 -64 and 160 -96 because I don't know why this is used. I need to create a rectangle that covers the left side of the screen and the same on the right. I want to create some on screen buttons, I have already created the actions for these buttons and I have managed to get them to work but I can't move the rectangles to where I want.

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

The two first numbers is the position of the lower left corner, the reason that they in some cases are written as one number minus another is to make it clear that the position is offset from a position other than (0,0), in the first case the upper right corner, which happens to be at position (319,479), the screen having the resolution or virtual resolution of 320x480. The third and fourth numbers are simply the width and height of the rectangle.

For a rectangle to the left you would use something like: new Rectangle(0, 0, 64, 480); for a rectangle that is 64 pixels wide and cover the entire screen height. For just a part of this bar you could do something like: new Rectangle(0, 128, 64, 64); for a rectangle that is 64 by 64 and 128 pixels off the bottom of the screen.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .