I tried using the MoveTo method in cocos2d to get a sprite to continuously follow my player sprite:
CCMoveTo actionMove = CCMoveTo.action(actualDuration, player.getPosition());
CCSequence actions = CCSequence.actions(actionMove);
enemy_sprite.runAction(actions);
However when the sprite spawns it just goes to the position the player sprite was at when it spawned, therefore it doesn't follow it continuously. So I tried using a recursive function to get the sprite to follow the player sprite continuously:
CCMoveTo actionMove = CCMoveTo.action(actualDuration, player.getPosition());
CCCallFuncN actionMoveDone = CCCallFuncN.action(this, "enemySpriteMoveFinished");
CCSequence actions = CCSequence.actions(actionMove, actionMoveDone);
enemy_sprite.runAction(actions);
Where "enemySpriteMoveFinished" is:
public void enemySpriteMoveFinished(Object sender) {
CCSprite sprite = (CCSprite)sender;
CCMoveTo actionMove = CCMoveTo.action(0.5f, player.getPosition());
CCCallFuncN actionMoveDone = CCCallFuncN.action(this, "enemySpriteMoveFinished");
CCSequence actions = CCSequence.actions(actionMove, actionMoveDone);
sprite.runAction(actions);
}
But this method turns out to be rather choppy. Anyone have any solution to getting cocos2d to move a sprite to a dynamic position continuously that's smoother?