I want to respawn enemy sprites based on a timer any suggestions would be appreciated.
Would be great if you show me some code examples.
-(void)addEnemyAtX:(int)x y:(int)y {
CCSprite *enemy = [CCSprite spriteWithFile:@"enemy1.png"];
enemy.position = ccp(x, y);
[self addChild:enemy];
[self animateEnemy: enemy];}
- (void) enemyMoveFinished:(id)sender {
CCSprite *enemy = (CCSprite *)sender;
[self animateEnemy: enemy];
}// a method to move the enemy 10 pixels toward the player
- (void) animateEnemy:(CCSprite*)enemy
{
// speed of the enemy
ccTime actualDuration = 0.3;
// Create the actions
id actionMove = [CCMoveBy actionWithDuration:actualDuration
position:ccpMult(ccpNormalize(ccpSub(player.position,enemy.position)), 10)];
id actionMoveDone = [CCCallFuncN actionWithTarget:self
selector:@selector(enemyMoveFinished:)];
[enemy runAction:
[CCSequence actions:actionMove, actionMoveDone, nil]];
}
I think you should learn the basics of Cocos2D first 😉 It’s pretty well covered in the book “Learning Cocos2D” – I recommend it!
Nevertheless here is the line of code you want, I doubt though, that it is useful 😉