Reputation: 1273
I'm creating some rectangles surrounding my sprites for my player and bullet class to detect collisions with the overlaps method in Intersector class of LibGDX.
I have a question:
When I instantiate Player and Bullet, I create a bounding box around the sprite using sprite.getBoundingRectangle() which returns a Rectangle object. I update the movement of these somewhere else in the main class.
When I update the movement of the bullet/player sprite, do I also need to update the position of the bounding box surrounding the bullet/player sprite? Or since the bounding Rectangle surrounds the sprite, will the box automatically move with the sprite?
Thanks
Upvotes: 4
Views: 2739
Reputation: 3102
As per getBoundingRectangle
javadoc:
Returns the bounding axis aligned Rectangle that bounds this sprite. The rectangles x and y coordinates describe its bottom left corner. If you change the position or size of the sprite, you have to fetch the triangle again for it to be recomputed.
Indeed, if you open Sprite
source code, you'll see that the bounding rectangle is updated only when getBoundRectangle
is called.
Upvotes: 1