Reputation: 3501
Here is my code, i have been trying-
-(void) animatedMove:(CCSprite *)character
{
ccTime actualDuration = 10;
id actionMove = [CCMoveBy actionWithDuration:actualDuration
position:ccp(screen_width+50, character.position.y)];
id actionBack = [CCMoveBy actionWithDuration:1
position:ccp(50, screen_height/2)];
id actionFinished = [CCCallFuncN actionWithTarget:self
selector:@selector(animatedMoveFinished:)];
[character runAction:[CCSequence actions:actionMove,actionBack,actionFinished,nil]];
}
-(void) animatedMoveFinished:(id)sender
{
CCSprite *character = (CCSprite *)sender;
[self animatedMove:character];
NSLog(@"( %.2f, %.2f", character.position.x, character.position.y);
}
its moving the character out of screen and not reinitializing to the start position.
Upvotes: 0
Views: 398
Reputation: 1401
Looks like you want it to appear from the left, exit the right, re-appear from the left, etc, etc ...
ccTime actualDuration = 10;
id actionMoveBy = [CCMoveBy actionWithDuration:actualDuration
position:ccp(screen_width+50, character.position.y];
id actionMoveTo = [CCMoveTo actionWithDuration: 0.0f position: character.position];
id actionSequence = [CCSequence actions: actionMoveBy, actionMoveTo, nil];
[character runAction: [CCRepeatForever actionWithAction: actionSequence]];
This will "loop forever" (due to the use of 'CCRepeatForever'), causing the character object to go from it's original starting position to the far right of the screen (using the ccp() math you were already applying), then immediately after it will "move instantly" (due to 0s duration) back to it's original starting position, and then repeat ...
Upvotes: 1