Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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