I am using below code to start Animation from left to right continuoulsy after some duration. Now at some point I want to stop this animation and want to start new Animation of that character.
But I am not able to do this, Can Anybody please help me for this?
here is my code
{
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"BoyIceFerrieAttack.plist "];
CCSpriteBatchNode *spriteSheet1 = [CCSpriteBatchNode batchNodeWithFile:@"BoyIceFerrieAttack.png"];
// Load up the frames of our animation
NSMutableArray *walkAnimFrames11 = [NSMutableArray array];
for(int i = 1; i <= 9; ++i)
{
[walkAnimFrames11 addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"iceferrieAttack%d.png", i]]];
}
CCAnimation *walkAnim11 = [CCAnimation animationWithFrames:walkAnimFrames11 delay:0.17f];
Adventurer * adventurer = [[Adventurer alloc] init];// autorelease];
if (adventurer != nil)
{
CGSize winSize = [CCDirector sharedDirector].winSize;
adventurer.charSprite = [CCSprite spriteWithSpriteFrameName:@"iceferrieWalk1.png"];
// Determine where to spawn the target along the Y axis
int minY = adventurer.charSprite.contentSize.height/4;//2;
int maxY = winSize.height - adventurer.charSprite.contentSize.height/2;
int rangeY = maxY - minY;
int actualY = (arc4random() % rangeY) + minY;
adventurer.charSprite.position = ccp(winSize.width + (adventurer.charSprite.contentSize.width/2), actualY);
CCAnimate *animate = [CCAnimate actionWithAnimation:walkAnim11 restoreOriginalFrame:NO];
CCSequence *seq = [CCSequence actions: animate, nil];
adventurer.walkAction = [CCRepeatForever actionWithAction: seq ];
// Determine speed of the target
int minDuration = 6.0;
int maxDuration = 16.0;
int rangeDuration = maxDuration - minDuration;
int actualDuration = (arc4random() % rangeDuration) + minDuration;
NSLog(@" actual duration: %i",actualDuration);
// Create the actions
id actionMove = [CCMoveTo actionWithDuration:actualDuration position:ccp(-adventurer.charSprite.contentSize.width/2, actualY)];
id actionMoveDone = [CCCallFuncN actionWithTarget:self selector:@selector(spriteMoveFinished

];
adventurer.moveAction = [CCSequence actions:actionMove, actionMoveDone, nil];
[adventurer.charSprite runAction:adventurer.walkAction];
[adventurer.charSprite runAction:adventurer.moveAction];
[self addChild:adventurer.charSprite z:2 tag:kTagEnemy];
[_targets addObject:adventurer.charSprite];
}
I tried to stop using this
[adventurer.charSprite stopAction:adventurer.walkAction];
[adventurer.charSprite stopAction:adventurer.moveAction];
but it is not stopping action with same char which is moving.
How to solve this?
Please Help.
Thanks,