Android Box2D 碰撞检测:如何测试特定边界?
我正在尝试使用 AndEngine 和 Box2D 物理插件制作一个简单的滑板游戏。我正在尝试制作“研磨”导轨,需要测试播放器的底部是否与研磨导轨的顶部发生碰撞;我知道执行此操作的常用方法是将碰撞盒的大小沿精灵的每个边缘调整为 1 像素并测试碰撞,但我不知道如何调整任何精灵主体的碰撞盒的大小。
我只会使用 Andengines 碰撞检测,但 box2Ds 碰撞检测和一般物理会阻止某些东西被检测为与 AndEngines 碰撞检测的碰撞,所以我一直在尝试为我的物理世界制作一个新的“ContactListener”,并使用“beginContact” (接触接触)'方法,但是区分正在碰撞的事物要困难得多,而且我不太确定我在做什么......
另外,我希望我的玩家能够通过在栏杆旁边(在它前面),但此刻我的播放器与其边缘相撞并停止。
目前,box2D 似乎比它的价值更多的努力,我很想把它从我的代码中剥离出来,只使用 AndEngines 碰撞检测来代替,并尝试我自己的简单物理......
I am trying to make a simple skateboarding game using AndEngine and the Box2D physics addon. I am trying to make a 'grind' rail and need to test if the bottom of my player is in collision with the top of the grind rail; I know the common way to do this is to resize the collision box to 1 pixel along each edge of the sprite and test for collision, but I have no idea how I can resize the collision box of any of my sprites bodies.
I would just use Andengines collision detection but box2Ds collision detection and general physics stop some things being detected as a collision with AndEngines collision detection, so I have been trying to make a new 'ContactListener' for my physics world and play around with the 'beginContact(Contact contact)' method, but differentiating between things that are colliding is a lot less straightforward and I'm not really sure what i'm doing...
Also, I would like the ability for my player to pass beside the rail (in front of it) but at the moment my player collides with its edges and stops.
At the moment box2D is seeming like more effort than its worth and I'm very tempted to rip it out of my code and just go with AndEngines collision detection instead and have a crack at my own simple physics...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将“用户数据”(类型:对象)附加到您创建的 Body 对象。我会创建某种 Userdata 类并扩展诸如 SkateBoardUserdata 和 GrindRailUserdata 之类的东西。
You can attach 'Userdata' (Type: Object) to the Body objects you create. I would make some kind of Userdata class and extend sth like SkateBoardUserdata and GrindRailUserdata.