我正在倾听动态机构之间的联系。但是不能听动态和静态物体之间的接触。
我可以使用此metod处理我的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;
}
Plz帮助我......
答案 0 :(得分:2)
静态体将是fixtureB,这不是一个有效的假设......它可能是fixtureA。
尝试测试一下......
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(fixtureA.GetBody().getUniqueBodyName() == "towerBody"){
//Towerbody is static body
trace("BINGOOOOOO - A");
}
if(fixtureB.GetBody().getUniqueBodyName() == "towerBody"){
//Towerbody is static body
trace("BINGOOOOOO - B");
}
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;
}