联系人侦听器问题 我不太了解C++,我正在尝试用COCOS2D-BOX2D实现()。这是联系人侦听器
subcontactlistener.h:联系人侦听器问题 我不太了解C++,我正在尝试用COCOS2D-BOX2D实现()。这是联系人侦听器,c++,cocos2d-iphone,box2d,box2d-iphone,C++,Cocos2d Iphone,Box2d,Box2d Iphone,subcontactlistener.h: #import <Foundation/Foundation.h> #import "cocos2d.h" #import "Box2D.h" #import <vector> typedef std::pair<b2Fixture*, b2Fixture*> fixturePair; typedef std::vector<fixturePair> thingsThatTouched; extern
#import <Foundation/Foundation.h>
#import "cocos2d.h"
#import "Box2D.h"
#import <vector>
typedef std::pair<b2Fixture*, b2Fixture*> fixturePair;
typedef std::vector<fixturePair> thingsThatTouched;
extern thingsThatTouched g_touchingFixtures;
class SubcContactListener : public b2ContactListener {
public:
void BeginContact(b2Contact* contact);
void EndContact(b2Contact* contact);
};
我得到一份工作
Expected unqualified-id
线路错误
thingsThatTouched.push_back( make_pair(contact->GetFixtureA(), contact->GetFixtureB()) );
在subcontactListener.mm的BeginContact方法中。
我也得到了一份工作
Unexpected type name 'thingsThatTouched': expected expression
线路错误
b2Fixture* fixtureA = thingsThatTouched[i].first;
b2Fixture* fixtureB = thingsThatTouched[i].second;
在HelloWorldLayer类的tick方法中
更新:
我试图在两个精灵(它们有自己的类)碰撞时创建焊接接头。下面是我在HelloWorld.mm的勾选方法中所做的:
b2WeldJoint *weldJoint;
b2WeldJointDef weldJointDef;
for (int i = 0; i < touchingBodies.size(); i++) {
b2Body* bodyA = touchingBodies[i].first;
b2Body* bodyB = touchingBodies[i].second;
weldJointDef.Initialize(bodyA, bodyB, bodyA->GetWorldCenter());
weldJointDef.collideConnected = false;
weldJoint = (b2WeldJoint*)world->CreateJoint(&weldJointDef);
}
touchingBodies.clear();
触摸的东西是一个typedef。它只是类型的同义词,而不是标识符/变量。换句话说,它本身不是一个物体。我想你应该在你使用触摸装置的地方使用触摸装置
当你说
typedef int myOwnInt;
现在你不能用
myOwnInt = 10; // Wrong. myOwnInt is just a type like how int is.
myOwnInt i = 10;
希望有帮助 嗯。什么是\u touchingBodies
哪个链接器在抱怨?如果它有extern
链接,您是否也在编译该文件以及当前源文件?extern thingsthatthatthetouchingbodies代码>是的,我将两者一起编译。touchingBodies
位于contactListerner.h
文件中。g\u touchingfights
定义在哪里?很抱歉没有提及。我将其替换为touchingBodies
,因为我想创建一个weldJoint
。我还将typedef的
更改为采用b2Body
而不是b2Fixture
typedef int myOwnInt;
myOwnInt = 10; // Wrong. myOwnInt is just a type like how int is.
myOwnInt i = 10;