0

私はC++をあまり知らないので、Cocos2d-box2dを使用して見つけたソリューションを実装しようとしています-(Box2Dで世界のcontactListenerを取得する)。これが連絡先リスナーです。

SubcContactListener.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 thingsThatTouched g_touchingFixtures;

class SubcContactListener : public b2ContactListener    {

public:

    void BeginContact(b2Contact* contact);
void EndContact(b2Contact* contact);
};

SubcContactListener.mm:

#import "SubcContactListener.h"

void SubcContactListener:: BeginContact(b2Contact *contact) {

    thingsThatTouched->push_back( make_pair(contact->GetFixtureA(), contact->GetFixtureB()) );

}

void SubcContactListener:: EndContact(b2Contact *contact)   {

}

私は

Expected unqualified-id

行でのエラー

thingsThatTouched.push_back( make_pair(contact->GetFixtureA(), contact->GetFixtureB()) );

SubcContactListener.mmのBeginContactメソッドで。私も

Unexpected type name 'thingsThatTouched': expected expression

行でのエラー

b2Fixture* fixtureA = thingsThatTouched[i].first;
b2Fixture* fixtureB = thingsThatTouched[i].second;

HelloWorldLayerクラスのtickメソッドで。

更新しました:

2つのスプライト(独自のクラスを持つ)が衝突したときに、溶接ジョイントを作成しようとしています。HelloWorld.mmのtickメソッドで行ったことは次のとおりです。

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();

しかし、次のエラーが発生します。

Apple Mach-O Linker (Id) Error
"_touchingBodies", referenced from:
  SubcContactListener::BeginContact(b2Contact*) in SubcContactListener.o
4

1 に答える 1

0

thingsThatTouchedtypedefです。これは型と同義ですが、識別子/変数ではありません。言い換えれば、それ自体はオブジェクトではありません。g_touchingFixtures使用している場所で使用することになっていると思いますthingsThatTouched

あなたが言う時、

typedef int myOwnInt;

今は使えません、

myOwnInt = 10;   // Wrong. myOwnInt is just a type like how int is.

myOwnInt i = 10; 

それが役に立てば幸い !

于 2012-07-12T13:50:38.357 に答える