Hello everyone,
I have yet another hurdle to get over with my code and was hoping the endless pit of knowledge that is the cocos2d forums could help!
I have a problem with some actions and animation i am running on a small number of atlas sprites, I set them on screen running an animation and action forever in a loop, that works fine, when they are hit and taken off screen i stop all animation and actions and drop them down on the screen for reuse with another action and attempt to put them in a loop moving and animating again. The problem is they drop down after being hit and start to run the actions and animation but each ship that lands cancels the last ones actions and only the last ship is left moving! Not to mention it crashes occasionally due to uncaught exception when trying to change actions.
Here is the code that handles the dead ships,
-(void) updateEnemy {
int i = 0;
for(Enemy *e in enemyarray){
if ([e moving]){
[e setDead: NO];//stops ship dying while moving into position
}
if ([e getDead]){
i++;
[e stopAllActions];
e.position = cpv(60*i,600);//places dead ships off screen
[e setDead: NO];
a7 = [MoveBy actionWithDuration:2 position:ccp(0,-400)];
action7 = [[[a7 copy] autorelease]retain];
[e runAction: action7]; //Drops ship into view
[e setMoving: YES];
[e runAction: action1]; //runs ship animation
}
if ([e moving] && e.position.y < 210){
[e setMoving: NO];
[e stopAllActions];
[e runAction: action5]; //starts ships moving again after dropping in
[e runAction: action1]; //starts ship anim again
}
else{
i++;
}
if(i == 4){
i = 0;
}
}
}
the actions that they intially run when first on screen are here,
for(Enemy *e in enemyarray)
{
if([e ready])
{
[e setMoving: NO];
[e setReady: NO];
[self addBodyToEnemy:e];
a5 = [MoveBy actionWithDuration:1 position:ccp(0,160)];
action1 = [RepeatForever actionWithAction:[[a1 copy] autorelease]];// ship animation
action5 = [[RepeatForever actionWithAction: [Sequence actions: [[a5 copy] autorelease], [a5 reverse],nil]]retain];// ship movement loop
[e runAction: action5];
[e runAction: action1];
}
}
Im not sure if it just me setting up my actions wrong or just my enemy handling code is real bad.
Any advice as always is welcome.