简体   繁体   English

libgdx - 围绕一个点旋转碰撞

[英]libgdx - rotating collisions around a point

for (int i = 0; i < 13; i++) {
            circleSprites.get(i).setOrigin(circleSprites.get(4).getX(), circleSprites.get(4).getY());
            circleSprites.get(i).rotate(20 * delta);
            circleCollisions.get(i).setPosition(circleSprites.get(i).getX() + 1, circleSprites.get(i).getY() + 1);
        }
        for (int i = 13; i < 26; i++) {
            circleSprites.get(i).setOrigin(circleSprites.get(17).getX(), circleSprites.get(17).getY());
            circleSprites.get(i).rotate(-20 * delta);
            circleCollisions.get(i).setPosition(circleSprites.get(i).getX() + 1, circleSprites.get(i).getY() + 1);
        }

Want something like this!想要这样的东西 The sprite is not rottating as indended, but I can figure that out.精灵并没有像预期的那样旋转,但我可以弄清楚。 But the thing is that .rotate does it just visually, I checked the coordinates and they stayed the same.但问题是 .rotate 只是在视觉上做到这一点,我检查了坐标,它们保持不变。 So how do I set up collision for a rotation like in the picture above?那么如何为上图所示的旋转设置碰撞?

LibGDX has a Intersector class which is useful in these situations. LibGDX 有一个 Intersector 类,在这些情况下很有用。

it has multiple methods for all types of geometric shapes to test intersection against each other.它有多种方法可以用于所有类型的几何形状来测试彼此的相交。

first you would need to give each of these sprites a Circle首先你需要给每个精灵一个圆圈

com.badlogic.gdx.math.Circle circle = new Circle(x,y,r);

then move these with your sprites so we have a geometric representation to test against(these Circles will be what we check collisions with, not the sprites, so we need to move these Circles with the sprites they represent at all times).然后用你的精灵移动它们,这样我们就有了一个几何表示来测试(这些圆将是我们检查碰撞的对象,而不是精灵,所以我们需要始终用它们代表的精灵移动这些圆)。

then in every update check with the Intersector class all your circles against the things you wish to collide with, ie然后在与 Intersector 类的每次更新中检查所有圈子与您希望碰撞的事物,即

overlaps(Circle c, Rectangle r) 
overlaps(Circle c1, Circle c2) 

etc等等

https://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/math/Circle.html https://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/math/Circle.html

https://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/math/Intersector.html https://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/math/Intersector.html

see this post...看到这个帖子...

Circle and Polygon Collision with Libgdx Libgdx 的圆和多边形碰撞

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

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