0 Replies - 1209 Views - Last Post: 24 June 2012 - 02:52 PM

#1 dcoderist  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 24-June 12

creating a contact listener between a rope and a sprite

Posted 24 June 2012 - 02:52 PM

Hi,
I've been trying to create a contact listener between a rope (which I made using revoluteJoints) and a sprite so that a weldJoint is created on contact. I don't know what is going wrong with the code, i've been at it for a few days. Below is my contact listener code in the update method, I got the classes from contact listener classes from Ray Wenderlich's tutorial:
std::vector<MyContact>::iterator pos;
        for(pos = _contactListener->_contacts.begin();
            pos != _contactListener->_contacts.end(); ++pos) {
            MyContact contact = *pos;
           
            b2Body *bodyA = [sprite getSpriteBody];
            b2Fixture* _typeAFixture = bodyA->GetFixtureList();
           
            b2Body *bodyB = [[ropeArray objectAtIndex:0] getPhysicsBody];
            b2Fixture* _typeBFixture = bodyB->GetFixtureList();
           
            if ((contact.fixtureA == _typeAFixture) && (contact.fixtureB == _typeBFixture)) {           
                b2WeldJointDef weldJointDef;
                weldJointDef.Initialize(bodyA, bodyB, bodyA->GetWorldCenter());
                weldJointDef.collideConnected = false;
                weldJoint = (b2WeldJoint*)world->CreateJoint(&weldJointDef);
               
            }
        } 


I created the classes for the rope (which returns a PhysicsSprite and has been added to an array in the init method HelloWorldLayer.mm) and a sprite (I made a Spriter classes and made an instance of Spriter in the init method of HelloWorldLayer.mm).
I keep getting the error:
Thread 1: EXC_ACCESS_(code=2, address=0x64)


pointing to the line
b2Fixture* _typeAFixture = bodyA->GetFixtureList();


Please help, i've been at it for a while.

Is This A Good Question/Topic? 0
  • +

Page 1 of 1