box2d,如何检测静态和动态物体之间的碰撞
我正在聆听动态物体之间的接触。但无法聆听动静体之间的接触。
我可以使用此方法处理 b2contactListener 类上的碰撞检测。
public override function BeginContact(contact:b2Contact):void {
// getting the fixtures that collided
var fixtureA:b2Fixture=contact.GetFixtureA();
var fixtureB:b2Fixture=contact.GetFixtureB();
// if the fixture is a sensor, mark the parent body to be removed
if(fixtureB.GetBody().getUniqueBodyName() == "towerBody"){
//Towerbody is static body
trace("BINGOOOOOO");
}
if (fixtureA.GetBody().getUniqueBodyName() == "bomb"){
// Bomb is dynamic body
// main.gamePhysics.destroyBodyWhenCollide(fixtureA.GetBody());
var spr:Sprite = fixtureA.GetBody().GetUserData();
spr.alpha = 0;
fixtureA.GetBody().collisionDetected = true;
}
请帮帮我...
i am listening contact between dynamic bodies. But cannot listen contact between dynamic and static bodies .
I can handle collision detection on my b2contactListener class with this metod.
public override function BeginContact(contact:b2Contact):void {
// getting the fixtures that collided
var fixtureA:b2Fixture=contact.GetFixtureA();
var fixtureB:b2Fixture=contact.GetFixtureB();
// if the fixture is a sensor, mark the parent body to be removed
if(fixtureB.GetBody().getUniqueBodyName() == "towerBody"){
//Towerbody is static body
trace("BINGOOOOOO");
}
if (fixtureA.GetBody().getUniqueBodyName() == "bomb"){
// Bomb is dynamic body
// main.gamePhysics.destroyBodyWhenCollide(fixtureA.GetBody());
var spr:Sprite = fixtureA.GetBody().GetUserData();
spr.alpha = 0;
fixtureA.GetBody().collisionDetected = true;
}
Plz help me out...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
静态主体将是fixtureB 并不是一个有效的假设...它可能是fixtureA。
尝试测试一下...
It's not a valid assumption that the static body will be fixtureB... it could be fixtureA.
Try testing this out...