I'm learning Cocos and Chipmunk mostly through examples. Now trying to branch out a little bit. But I'm stuck.
Not sure if I'm even doing this correctly - but I've got 1 scene that I'm trying to initialize chipmunk:
TestScene.m
-(void) initChipmunk
{
// Start chipmunk
cpInitChipmunk();
space = cpSpaceNew();
space->gravity = cpv(0, -100);
}
I've got another class with my sprite that I'm trying to add to this scene with chipmunk
MyBox.m
-(id) init
{
if((self = [super init]))
{
Sprite *mySprite = [Sprite spriteWithFile:@"Icon.png"];
CGSize s = [[Director sharedDirector] winSize];
mySprite.position = ccp(s.width /2, s.height/2);
[self addChild:mySprite z:0];
body = cpBodyNew(100.0, INFINITY);
body->p = cpv(s.width /2, s.height/2);
cpSpaceAddBody(space, body);
shape = cpCircleShapeNew(body, 20.0, cpvzero);
shape->e = 0.5; // Elasticity
shape->u = 0.8; // Friction
shape->data = mySprite;
shape->collision_type = 1;
cpSpaceAddShape(space, shape);
}
return self;
}
My issue is I do not know how to call these files from my TestScene.m init: Right now I'm doing something like this.
TestScene.m
-(id) init
{
if((self = [super init]))
{
[self initChipmunk];
MySprite *icon = [MySprite node];
[self addChild:icon];
[self schedule: @selector(step:)];
}
return self;
}
I'm getting a build error in MyBox.m "error: 'space' undeclared (first use in function)"
I guess my chipmunk space is not present in the file, because its initialized in my scene file.
I'm not really sure if I'm going about this correctly, every demo/tutorial I've done has always added the chipmunk initialization, body creation, shape creation in one long block, I was looking to sorta compartmentalize some of that...