[英]Libgdx box2d how to get the current body position
Why doesn't this work? 为什么不起作用?
for (Body body : worldBodies) {
if (body.getPosition().y<0)
{
sprite.setColor(Color.GREEN);
}
}
Please notice that body origin is at its center so what you should check is actually 请注意,身体起源在其中心,因此您应该检查的实际上是
if (body.getPosition().y - bodyShapeHeight/2f < 0 ) //bodyShapeHeight is just a variable you have to create
{
...
Unfortunately there is no like bodyHeight - it depends on Fixture. 不幸的是,没有像bodyHeight这样的东西-它取决于治具。 If you have only one and its aligned to center you probably can use 如果只有一个,并且其居中对齐,则可以使用
body.getFixtureList().first().getShape().getRadius();
instead of using additional variable but if not you have to remember shape height in some bodyShapeHeight variable 而不是使用其他变量,但如果没有,则必须记住某些bodyShapeHeight变量中的形状高度
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.