Hey all,
I seem to be having trouble with getting an action to run for one of my game objects, i have a rock object stored in an nsmutablearray with some chipmunk and sprite data attached and it doesnt seem to want to accept the action, it tells me there is an uncaught exception and rock wont respond because there is 'no matching method signature'.
This is my rock object which is sperate from game layer for the most part.
@implementation Rock
-(id) initWithCPBodyRock: (cpBody *) bodyIn
{
self = [super init];
if(self != nil){
rockBod = bodyIn;
ready = YES;
}
return self;
}
-(void)updateRockBodyPosX: (float) x Y:(float)y
{
rockBod->p = cpv(x,y);
rockBod->v = cpv(0, 0);
}
And the relevant part of the main program loop in my game layer with relevant methods
rocks = [[NSMutableArray alloc] init];
for(int i = 0; i < 1; i++)
{
Rock *r = [[Rock alloc] initWithCPBodyRock:
[self makeSpaceRockX:200 y:200]];
[rocks addObject: r];
[r release];
}
[self moveRock];
[self schedule: @selector(updateRock:)];
}
return self;
}
-(void) updateRock{ //syncs chipmunk body
for (Rock *r in rocks) {
[r updateRockBodyPosX: rocky.position.x Y:rocky.position.y];
}
}
-(void) moveRock {
for (Rock *r in rocks) {
a1 = [MoveBy actionWithDuration:2 position:ccp(100,100)];
action1 = [RepeatForever actionWithAction: [Sequence actions: [[a1 copy] autorelease], [a1 reverse], nil]];
[r runAction: action1]; // the part that it gets stuck at!!!!
}
}
-(cpBody *) makeSpaceRockX: (float) x y:(float)y {
rocky = [[Sprite spriteWithFile:@"rock.png"] retain];
rocky.position = cpv(x,y);
[self addChild: rocky];
cpVect verts[] = {
cpv(-54,-43),
cpv(-54, 43),
cpv(54, 43),
cpv(54,-43),
};
cpBody *rockyBody = cpBodyNew(200.0f, INFINITY);
rockyBody->p = cpv(x,y);
rockyBody->v = cpv(0, 0);
cpSpaceAddBody(space, rockyBody);
cpShape * rockyShape = cpPolyShapeNew(rockyBody, 4, verts, cpvzero);
rockyShape->e = 0.9f; rockyShape->u = 0.9f;
rockyShape->data = rocky;
rockyShape->collision_type = 0; //New!
cpSpaceAddShape(space, rockyShape);
cpSpaceAddCollisionPairFunc(space, 0, 3, &bulletCollision, self); //Also new!
return rockyBody;
}
The action works if i use a simple sprite initiated in the main program loop, but it just doesnt like my rock for whatever reason.
Sorry i hope i'm not spamming to much code here, any help or ideas would be appreciated greatly.