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

  • SEARCH
  • Home
  • 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 6698991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:38:33+00:00 2026-05-26T06:38:33+00:00

My problem is that animation are not working properly during movements of sprite. Below

  • 0

My problem is that animation are not working properly during movements of sprite.
Below is the code which i’m using

- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event {    

    [selSprite resumeSchedulerAndActions];
    CGPoint touchLocation = [self convertTouchToNodeSpace:touch];
    [self selectSpriteForTouch:touchLocation];   
    return TRUE;    
}

- (void)selectSpriteForTouch:(CGPoint)touchLocation  
{
 CCSprite * newSprite = nil;

    for (CCSprite *sprite in movableSprite) {
        if (CGRectContainsPoint(sprite.boundingBox, touchLocation)) {            
            newSprite = sprite;
            break;
        }
    }    
    if (newSprite != selSprite) {
        [selSprite stopAllActions];

        selSprite = newSprite;

        _MoveableSpritetouch = TRUE;
    }

    if(_MoveableSpritetouch==TRUE)
    {
      movement=0;
CGRect selRect=CGRectMake((SpriteX)-20.0,(SpriteY)-20.0,40.0,40.0);
        if(CGRectContainsPoint(selRect, touchLocation))
        {  
            [selSprite stopAllActions];


        }
 if((selSprite==MarshallCar)&& (!(CGRectContainsPoint(selRect, touchLocation)))) 
        {
            movement=1;
            [self reorderChild:selSprite z:5];


            NSMutableArray *MarshallCarWalkAnimFrames = [NSMutableArray array];
            for(int i = MarshallCarTouchStartFrameIndex; i <= MarshallCarTouchEndFrameIndex; ++i) {
                [MarshallCarWalkAnimFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"mcar_move_%d.png", i]]];
            }
            MarshallCarWalkAnim = [CCAnimation animationWithFrames:MarshallCarWalkAnimFrames delay:MarshallCarTouchFrameDelay];
            walkMarshallCar = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:MarshallCarWalkAnim restoreOriginalFrame:NO]];


            [selSprite runAction:walkMarshallCar];
        }
}
}

- (void)ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event {       


    if(gameState == TRUE){


        CGPoint point = [touch locationInView:[touch view]];
        point = [[CCDirector sharedDirector] convertToGL:point];
        if (moveDifference.x>0)
                    { 
                        selSprite.flipX = YES;
                    } 

                    else {
                        selSprite.flipX = NO;
                    } 
         [selSprite setPosition:point];


     }
  }

-(void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event
{   
    movement=0;
if(selSprite==MarshallCar)
    { 
        [selSprite setDisplayFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"mcar_idle.png"]];

    }
[selSprite pauseSchedulerAndActions];
}

The animation frames for movement are not playing every time during movements sometimes it plays or sometimes not. It plays properly when you touch and move your sprite for the first time but if touch another sprite and then again move the previous sprite the animations for movement won’t play.

Is anyone having any idea why this is happening?
Please tell me the proper code for removing this bug.
Thanks!!!

  • 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-05-26T06:38:34+00:00Added an answer on May 26, 2026 at 6:38 am
    if((selSprite==MarshallCar)&& (!(CGRectContainsPoint(selRect, touchLocation)))) 
            {
                movement=1;
                [self reorderChild:selSprite z:5];
    
    
                NSMutableArray *MarshallCarWalkAnimFrames = [NSMutableArray array];
                for(int i = MarshallCarTouchStartFrameIndex; i <= MarshallCarTouchEndFrameIndex; ++i) {
                    [MarshallCarWalkAnimFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"mcar_move_%d.png", i]]];
                }
                MarshallCarWalkAnim = [CCAnimation animationWithFrames:MarshallCarWalkAnimFrames delay:MarshallCarTouchFrameDelay];
                walkMarshallCar = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:MarshallCarWalkAnim restoreOriginalFrame:NO]];
    
    
                [selSprite runAction:walkMarshallCar];
            }
    

    I have added [selSprite stopAllActions];
    and it started working correctly because in the touch ended method i was pausing the actions
    but not resuming them so when i touch the sprite for the second time it was not playing animation because the action was paused.

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

Sidebar

Related Questions

I have a problem that I'm working on for quite some time now. I
I have created a quick jsfiddle here showing it not working. The problem I
I am working on an animated jQuery menu using Spritely the problem I have
I'm currently working on a project that requires animation on a transparent panel. I
As per my previous question , I have a working animation which fades in
Hey guys I'm working on a jQuery code snippet that's suppose to remove a
I am using flip plug-in in jQuery which flips a given div. The code(reusing
The problem is that when I try doing multiple animations they all happen the
Simple problem that I can't figure out... How can I print a '%' character
The problem that I have is somehow very specific. I have to implement a

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.