I want to run an action and go on go on processing game logic at the same time, but action is interrupted when the process is going on. I tried to use thread, but I couldn't make it work. When it's not needed to process game logic the sprites move as I expected, but when it's needed to make some operations during action, the action is interrupted during the operation time. After the operation is ended, the action is going on. What am I doing wrong?
I call a selector as follows - the selector starts the action.
[NSThread detachNewThreadSelector:@selector(moveSprite:)
toTarget:self
withObject:[NSDictionary dictionaryWithObjectsAndKeys:
sprite, @"sprite",
[NSValue valueWithCGPoint:pos], @"pos",
nil]];
-(void) moveSprite: (NSDictionary*) parameters {
CCSprite *sprite = [parameters objectForKey:@"sprite"];
CGPoint pos = [[parameters objectForKey:@"pos"] CGPointValue];
id actionMove = [CCMoveTo actionWithDuration:0.4f position:pos];
id actionMoveDone = [CCCallFuncND actionWithTarget:self selector:@selector(removeSprite:data:) data:(__bridge void*)sprite];
[sprite runAction:[CCSequence actions:actionMove, actionMoveDone, nil]];
}
After the action ends I remove the sprite by following method.
-(void) removeSprite: (id)sender data:(void*)data {
CCSprite *sprite = (__bridge CCSprite*)data;
[self removeChild:sprite cleanup:YES];
}