Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9271523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:38:15+00:00 2026-06-18T15:38:15+00:00

I am having problem in stoping action. i have 2 sprite animation 1 is

  • 0

I am having problem in stoping action. i have 2 sprite animation 1 is ant and second is grasshopper. WHen i am just calling ants animation it works fine but when i try to run both ant and grasshopper animation it gives me error.
* Assertion failure in -[CCSpriteBatchNode addChild:z:tag:], /Users/zohaib/Downloads/zohaibgame/zohaibgame/libs/cocos2d/CCSpriteBatchNode.m:183
it gives error when antMoveEnded is called.

ants animation code

-(void) walk_Ants
{

    // 1) Cache the sprite frames and texture
    [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:
     @"ant-animation.plist"];

    /// 2) Create a sprite batch node
    CCSpriteBatchNode *spriteSheet_ant = [CCSpriteBatchNode
                                          batchNodeWithFile:@"ant-animation.png"];
    [self addChild:spriteSheet_ant];

    // 3rd Step
    // 3) Gather the list of frames
    NSMutableArray *walkAnimFrames = [NSMutableArray array];
    for(int i = 1; i <= 24; ++i) {
        [walkAnimFrames addObject:
         [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
          [NSString stringWithFormat:@"%d.png", i]]];

    }

    // 4th Step
    // 4) Create the animation object
    CCAnimation *walkAnim = [CCAnimation
                             animationWithSpriteFrames:walkAnimFrames delay:0.05f];

    // 5th Step
    // 5) Create the sprite and run the animation action
    self.ants = [CCSprite spriteWithSpriteFrameName:@"1.png"];
    _ants.position = ccp(winSize.width, winSize.height/6);
    //_ants.position = ccp(459, 16);
    self.walkActionAnt = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:walkAnim]];
    [_ants runAction:_walkActionAnt];
    [spriteSheet_ant addChild:_ants];
    CCLOG(@"Position %@",NSStringFromCGPoint(_ants.position));
    [self walkingAnts];


}

-(void) walkingAnts
{
    // 2) Set the desired velocity
    float antVelocity = 480.0/10.0;

    // 3) Figure out the amount moved in X and Y
    CGPoint waking_Path = CGPointMake(X_AXIS_ENDINGPATH, _ants.position.y);
    CGPoint moveDifference = ccpSub(waking_Path, _ants.position);

    // 4) Figure out the actual length moved
    float distanceToMove = ccpLength(moveDifference);

    // 5) Figure out how long it will take to move
    float moveDuration = distanceToMove / antVelocity;

    // 7) Run the appropriate actions
    //[_ants stopAction:_moveAction];


    id restartAntWalk = [CCCallFuncN actionWithTarget:self selector:@selector(antMoveEnded:)];

    self.moveActionAnt = [CCSequence actions:
                       [CCMoveTo actionWithDuration:moveDuration position:waking_Path],
                       restartAntWalk,
                       nil];
    //self.moveActionAnt.tag = 121;
    [_ants runAction:_moveActionAnt];
    _movingAnt = TRUE;

}

- (void) antMoveEnded: (ccTime) dt
{
    if(_ants.position.x == -50)
    {
        [_ants stopAction:_moveActionAnt];
        //[self stopActionByTag:121];
        _movingAnt = FALSE;
        [self walk_Ants];
    }
}

GrassHopper code ( mantis )

-(void) mantisCome
{
    float w_index = arc4random() % 480;
    //float h_index = arc4random() % 320;

    self.moveActionMantis = [CCSequence actions:
                             [CCMoveTo actionWithDuration:2 position:ccp(w_index, 63)],

                             nil];

    [_mantis runAction:_moveActionMantis];
    [self schedule:@selector(timer:) interval:5];

}

-(void) mantisGo
{
    self.moveActionMantis = [CCSequence actions:
                             [CCMoveTo actionWithDuration:2 position:ccp(-50, 280)],

                             nil];

    [_mantis runAction:_moveActionMantis];
    [self unschedule:@selector(timer:)];
    [self mantisAnimation];
}

#pragma -mark Mantis Animation
-(void) mantisAnimation
{

    // 1) Cache the sprite frames and texture
    [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:
     @"mantis-animation.plist"];

    /// 2) Create a sprite batch node
    CCSpriteBatchNode *spriteSheet_mantis = [CCSpriteBatchNode
                                             batchNodeWithFile:@"mantis-animation.png"];
    [self addChild:spriteSheet_mantis];

    // 3rd Step
    // 3) Gather the list of frames
    NSMutableArray *walkAnimFrames_mantis = [NSMutableArray array];
    for(int i = 1; i <= 14; ++i) {
        [walkAnimFrames_mantis addObject:
         [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
          [NSString stringWithFormat:@"%d.png", i]]];

    }

    // 4th Step
    // 4) Create the animation object
    CCAnimation *walkAnim_mantis = [CCAnimation
                                    animationWithSpriteFrames:walkAnimFrames_mantis delay:0.05f];

    // 5th Step
    // 5) Create the sprite and run the animation action
    self.mantis = [CCSprite spriteWithSpriteFrameName:@"1.png"];
    _mantis.position = ccp(winSize.width+100, winSize.height+100);
    _mantis.flipX=YES;
    //_mantis.position = ccp(459, 16);
    self.walkActionMantis = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:walkAnim_mantis]];
    walkAnim_mantis.restoreOriginalFrame = NO;
    [_mantis runAction:_walkActionMantis];
    [spriteSheet_mantis addChild:_mantis];
    //CCLOG(@"Position %@",NSStringFromCGPoint(_mantis.position));
    [self mantisCome]; 
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T15:38:17+00:00Added an answer on June 18, 2026 at 3:38 pm

    I figured out what was the problem.
    when i was creating animation for ant i was using this code

    NSMutableArray *walkAnimFrames = [NSMutableArray array];
        for(int i = 1; i <= 24; ++i) {
            [walkAnimFrames addObject:
             [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
              [NSString stringWithFormat:@"%d.png", i]]];
    
        }
    
    self.ants = [CCSprite spriteWithSpriteFrameName:@"1.png"];
    

    and when creating animaiton for mantis

    NSMutableArray *walkAnimFrames_mantis = [NSMutableArray array];
        for(int i = 1; i <= 14; ++i) {
            [walkAnimFrames_mantis addObject:
             [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
              [NSString stringWithFormat:@"%d.png", i]]];
    
        }
    
    self.mantis = [CCSprite spriteWithSpriteFrameName:@"1.png"];
    

    i was using 1.png for both. self.ant and self.mantis. i created a new plist file and changed png name from 1.png to ant1.png . It works now.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a problem relating to storing a variable within Javascript. I have a
Im having problem in my UIscrollView ,this is what I have done: Whenever a
I'm having problem with datagrid view. I have attached an image with the code
hello I am having problem related to https:// . I have used FB.getLoginStatus(function(response) function
I am having a problem of storing the string that I have build with
I have a multilingual site and I am having a problem inserting Chinese meta
I'm having a problem stopping the 'feed'; the cancel argument doesn't seem to have
I'm having a problem where when I try to select the rows that have
Can anyone help with a small problem I am having, I have WCF Rest
I'm having a problem and im tired of searching for the answer.. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.