Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Game Development

Reply
 
LinkBack Thread Tools Display Modes
Old 12-29-2011, 08:08 AM   #1 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 19
goldenlife is on a distinguished road
Default How to stop Animation once started with CCSpriteBatchNode in Cocos2d

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,
goldenlife is offline   Reply With Quote
Old 01-03-2012, 10:23 AM   #2 (permalink)
Registered Member
 
Join Date: Jan 2009
Posts: 280
dapis is on a distinguished road
Default

You would probably be far more likely to get a helpful response at a cocos2d forum such as:

cocos2d for iPhone
dapis is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 385
9 members and 376 guests
apatsufas, comicool, Creativ, dansparrow, husthlj, LunarMoon, mer10, Murphy, pbart
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,677
Threads: 94,127
Posts: 402,916
Top Poster: BrianSlick (7,990)
Welcome to our newest member, husthlj
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 07:04 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0