Hi, I am using cocos2d and am trying to initialize an actor class with body, and fixture already set when adding to world. I have the body working, but the shape of the fixture doesn't seem to get recognized. Does anyone know why this would be?
Thanks
Code:
/// SolidGameObject.h
@interface SolidGameObject : Layer
{
GameObject *object; // for textures
b2Body *body;
b2BodyDef *bodyDef;
b2CircleShape *shapeDef;
b2FixtureDef *fixtureDef;
}
- (id)initWithWorld:(b2World *)wrld andCoords:(CGPoint)p;
@property (nonatomic, retain) GameObject *object;
@property (nonatomic, assign) b2Body *body;
@property (nonatomic, assign) b2BodyDef *bodyDef;
@property (nonatomic, assign) b2CircleShape *shapeDef;
@property (nonatomic, assign) b2FixtureDef *fixtureDef;
@end
/// SolidGameObject.mm
#define PTM_RATIO 32
@implementation SolidGameObject
@synthesize object, body, bodyDef, shapeDef, fixtureDef;
- (id)initWithWorld:(b2World *)wrld andCoords:(CGPoint)p
{
if( (self=[super init]) )
{
self.relativeAnchorPoint = NO;
object = [GameObject gameObject];
[self addChild:object z:1 tag:10];
// THE BODY DEF
[self setBodyDef:new b2BodyDef];
[self bodyDef]->isBullet = true;
[self bodyDef]->fixedRotation = true;
[self bodyDef]->position.Set(p.x/PTM_RATIO, p.y/PTM_RATIO);
// THE ACTUAL BODY
body = wrld->CreateBody([self bodyDef]);
// THE CIRCLE SHAPE
[self setShapeDef:new b2CircleShape];
[self shapeDef]->m_radius = 3.0f/PTM_RATIO;
// THE FIXTURE
[self setFixtureDef:new b2FixtureDef];
[self fixtureDef]->shape = shapeDef;
[self fixtureDef]->friction = 0.0f;
[self fixtureDef]->density = 0.0f;
[self fixtureDef]->restitution = 0.8f;
body->CreateFixture([self fixtureDef]);
body->SetUserData(object);
}
return self;
}
@end
///GameLayer.mm
SolidGameObject *solid = [[[SolidGameObject alloc] initWithWorld:world andCoords:CGPointMake(240,40)] autorelease];
[self addChild:solid z:4 tag:10];