简体   繁体   English

LibGDX碰撞边界矩形

[英]LibGDX collision bounding Rectangle

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. 我正在为我的播放器和项目符号类创建一些围绕精灵的矩形,以检测LibGDX的Intersector类中的overlays方法的冲突。

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. 实例化Player和Bullet时,我使用sprite.getBoundingRectangle()在Sprite周围创建了一个边界框,该边界框返回一个Rectangle对象。 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 谢谢

As per getBoundingRectangle javadoc : 根据getBoundingRectangle javadoc

Returns the bounding axis aligned Rectangle that bounds this sprite. 返回绑定此sprite的边界轴对齐的Rectangle。 The rectangles x and y coordinates describe its bottom left corner. 矩形x和y坐标描述了其左下角。 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. 确实,如果打开Sprite 源代码 ,您将看到仅在调用getBoundRectangle时才更新边界矩形。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM