我设置了一个接触监听器,当两个物体之间建立接触时,它会创建一个焊接接头。当身体接触时,我不断收到指向线的 SIGABRT
b2Assert(IsLocked() == false);
在方法中
b2Joint* b2World::CreateJoint(const b2JointDef* def)
班内
b2World.cpp
以下是联系人监听器类:SubcContactListener.h:
#import <Foundation/Foundation.h>
#import "cocos2d.h"
#import "Box2D.h"
#import "Spriter.h"
#import "CreateRope.h"
class SubcContactListener : public b2ContactListener {
public:
void *helloWorldLayer;
b2WeldJoint *weldJoint;
b2World *world;
void BeginContact(b2Contact* contact);
void EndContact(b2Contact* contact);
void createWeldJoint(b2Body* ABody ,b2Body* BBody);
//void destroyWeldJoint(b2WeldJoint *weldJoint);
};
SubcContactListener.mm:
#import "SubcContactListener.h"
#import "HelloWorldLayer.h"
void SubcContactListener:: BeginContact(b2Contact *contact) {
}
void SubcContactListener:: EndContact(b2Contact *contact) {
b2Fixture *fixtureA = contact->GetFixtureA();
b2Fixture *fixtureB = contact->GetFixtureB();
b2Body *fixtureABody = fixtureA->GetBody();
b2Body *fixtureBBody = fixtureB->GetBody();
// We don't care about collisions that don't involve two bodies.
if (helloWorldLayer && fixtureABody && fixtureBBody)
{
if(fixtureABody != NULL && fixtureBBody != NULL){
createWeldJoint(fixtureABody, fixtureBBody);
}
}
}
void SubcContactListener:: createWeldJoint(b2Body* ABody ,b2Body* BBody) {
// The sprite tag is 1 for the spriter sprite and 3 for the rope links.
if (ABody && BBody)
//{
CCSprite *bodyASprite = (CCSprite *) ABody->GetUserData();
CCSprite *bodyBSprite = (CCSprite *) BBody->GetUserData();
NSInteger bodyASpriteTag = bodyASprite.tag;
NSInteger bodyBSpriteTag = bodyBSprite.tag;
if (((bodyASpriteTag == 1) && (bodyBSpriteTag == 3)) ||
((bodyASpriteTag == 3) && (bodyBSpriteTag == 1)))
{
//creation of weldjoint
if ( ABody!= NULL && BBody != NULL) {
b2WeldJointDef weldJointDef;
weldJointDef.Initialize(ABody,
BBody,
ABody->GetWorldCenter());
weldJointDef.collideConnected = false;
weldJoint = (b2WeldJoint*) ABody->GetWorld()->CreateJoint(&weldJointDef);
}
}
}
}
同样在 HelloWorldLayer.mm initPhysics 方法中:
// Create contact listener
contactListener = new SubcContactListener();
contactListener->helloWorldLayer = self;
world->SetContactListener(contactListener);
从错误中我认为它与焊接接头有关,只是不太确定。请帮忙。