title: Adding to b2world, external box2d bodies from external classes
body: <p>using obj-c box2d and cocos2d, im attempting to create my box2d objects in a separate Class, for convenience sake and to group objects together.<br>
  Basically, I have two Classes:  </p>
  
  <p>Constructor - The Box2d world is loaded and the OpenGL draw methods exist here<br>
  Gate - A Class that has multiple objects, two sprites, a Door sprite and a Switch sprite with their own bounding boxes etc.  </p>
  
  <p>At the moment I have this:</p>
  
  <pre><code>@interface Gate : CCNode {
  @private
      //Door Gadget:
      b2Body *body_door;
      b2BodyDef def_door;
      b2FixtureDef fixtureDef;
      CGRect boundingBox_door;
      CCSprite *sprite_door;
  
  }
  -(void)createGate:(CGPoint)gateLoc:(CGPoint)switchLoc;
  @property (assign) CGRect boundingBox_door;
  @property (assign) CCSprite *sprite_door;
  @property (assign) b2Body *body_door;
  @property (assign) b2BodyDef def_door;
  @property (assign) b2FixtureDef fixtureDef;
  
  
  @end
  
  
  @implementation Gate
  
  -(void) createGate:(CGPoint)doorLoc:(CGPoint)switchLoc{
  //please note that these variables are global and synthesized inside the header file
  
      sprite_door = [CCSprite spriteWithFile:@"eggBIG.png"];
      sprite_door.position = gateLoc;
  
      //Gadget 1 - Door Physics Body
      def_door.type = b2_dynamicBody;                 
      def_door.position.Set(gateLoc.x/PTM_RATIO,gateLoc.y/PTM_RATIO);
      def_door.userData = sprite_door;                
  
      b2PolygonShape dynamic_block1;              
      dynamic_block1.SetAsBox(15.0f/PTM_RATIO, 15.0f/PTM_RATIO);
      fixtureDef.shape = &amp;dynamic_block1;
      fixtureDef.density = 3.0f;
      fixtureDef.friction = 1.0f;
  
  }
  </code></pre>
  
  <p>Constructor Class .mm - </p>
  
  <pre><code>@implementation Constructor
  -(id) init{
  //Create Gate
          Gate *gate = [[Gate alloc]init];
          [gate createGate:ccp(300,300) :ccp(400,400)];
          [self addChild:gate.sprite_door];
          b2BodyDef def_door = gate.def_door;
          gate.body_door = world-&gt;CreateBody(&amp;def_door);
          b2Fixture *doorFixture;
          b2FixtureDef fixtureDef = gate.fixtureDef;
          doorFixture = gate.body_door-&gt;CreateFixture(&amp;fixtureDef);
          doorFixture-&gt;SetUserData(@"sprite_door");
  }
  </code></pre>
  
  <p>Because this is objective-c++, i cannot directly add properties to the variables inside C Method. For example:<br>
  doorFixture = gate.body_door->CreateFixture(&amp;fixtureDef);
  cannot be:<br>
  doorFixture = gate.body_door->CreateFixture(&amp;gate.fixtureDef);  </p>
  
  <p>I'm not very proficient with C++, so this is a little daunting.<br>
  This is quite important for the architecture of my game, so please help :)</p>