简体   繁体   English

Slick2D碰撞检测

[英]Slick2D Collision Detection

我想知道是否有任何其他方法使用slick2D库进行碰撞检测,除了标准坐标方式(if(xpos <3 && ypos> 8))等。

Note: I do realize that this question is a bit old, yet this answer might help future visitors 注意:我确实意识到这个问题有点陈旧,但这个答案可能会对未来的访问者有所帮助

Yes, there are. 是的,有。

In Slick2D you can check for collisions between shapes with the Shape#intersects(Shape other) method. 在Slick2D中,您可以使用Shape#intersects(Shape other)方法检查形状之间的碰撞。

The Shape class already provides a lot of useful methods, but I suggest using the Rectangle class which is probably simpler to use for a simple game, as you do not have to care about Polygon transformations. Shape类已经提供了许多有用的方法,但我建议使用Rectangle类,它可能更简单地用于简单游戏,因为您不必关心Polygon转换。 Yet, if you wish to have more complex shapes you should use the Polygon class. 但是,如果您希望拥有更复杂的形状,则应使用Polygon类。 You will have to take care of some things yourself, so I recommend creating a Hitbox class extending the Polygon class, but with the Polygon approach you will be more flexible and you will be able to rotate your shapes (which is not possibly with the Rectangle class). 你必须自己处理一些事情,所以我建议你创建一个扩展Polygon类的Hitbox类,但是使用Polygon方法你会更灵活,你可以旋转你的形状(这可能不是Rectangle类)。

Resources 资源

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

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