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 6807099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:47:26+00:00 2026-05-26T19:47:26+00:00

i have a cocos2d world, and a sprite/body that is moving fast . when

  • 0

i have a cocos2d world, and a sprite/body that is moving fast .
when contact occur i am calling animation function.
The problem is , that when the animation is running in the current sprite position, the sprite was already gone to another place so animation is not in right place:

how would i run this animation function to follow my sprite ?

code:

-(void)animation:(NSString *)animation
{

    NSLog(@"check:%@",animation);


    [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:[NSString stringWithFormat:@"%@.plist",animation]];
    sprite = [CCSprite spriteWithSpriteFrameName:[NSString stringWithFormat:@"%@_00000.png",animation]]; //take the corrdinates of this picture from the plist

    sprite.position=boy.position;
    //sprite.position=ccp(160,175);

    CCSpriteBatchNode *spriteSheet = [ CCSpriteBatchNode batchNodeWithFile:[NSString stringWithFormat:@"%@.png",animation]];
    [spriteSheet addChild:sprite]; //add this coordinates from the spritesheet to the screen
    [self addChild:spriteSheet];


    NSString *Path = [[NSBundle mainBundle] bundlePath];
    NSString *animPath = [Path stringByAppendingPathComponent: [NSString stringWithFormat:@"%@.plist", animation]];
    NSDictionary *animSpriteCoords = [[NSDictionary alloc] initWithContentsOfFile: animPath];
    NSDictionary *animFramesData = [animSpriteCoords objectForKey:@"frames"];
    int b=0;
    int a=0;
    NSMutableArray *animFrames = [NSMutableArray array];
    for(int i = 1; i < [animFramesData count]; i++) 

    {
        a=a+1;
        if(a==10)
        {
            b=b+1;
            a=0;
        }


        CCSpriteFrame *frame = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"%@_000%0i%1i.png",animation,b,a]];   //[NSString stringWithFormat:@"eye_blinking_0000%1d.png",i]
        [animFrames addObject:frame];
    }


    //CCAnimation *dollAnimation = [CCAnimation animation];
    CCAnimation* dollAnimation = [CCAnimation animationWithFrames:animFrames delay:0.1f];
    //CCAnimation *dollAnimation = [CCAnimation animationWithName:@"dance" animationWithFrames:animFrames];
    //[dollAnimation setDelay:0.1f];
    CCAnimate * Action = [CCAnimate actionWithAnimation:dollAnimation];
    id call=[CCCallFunc actionWithTarget:self selector:@selector(finishAnimation)];
    id sequence=[CCSequence actions:Action,[CCHide action],call,nil];
    [sprite runAction:sequence];
}

thnaks a lot.

  • 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-26T19:47:26+00:00Added an answer on May 26, 2026 at 7:47 pm

    CCFollow will have the animation sprite follow the boy sprite:

    id follow = [CCFollow actionWithTarget:boy];
    [sprite runAction:follow];
    

    Alternative is to continuously update the animation sprite’s position to that of the boy position (sprite.position = boy.position) in a scheduled update method.

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

Sidebar

Related Questions

In a game that I am making whilst using Cocos2d, I have a sprite
I'm on cocos2d and I have a sprite that I would like to rotate
i am having this problem try to use the cocos2d CCScrollLayer I have added
I am learning Cocos2d and building an application where i have sprite at one
I have a Cocos2D iPhone application that requires a set of CGRects overlaid on
In Cocos2d, I have read that [[[[CCDirector sharedDirector] openGLView] window] addSubview:someButton]; will add a
If I have two objects in chipmunk (I'm using cocos2d-iphone), once I've detected that
Alright, here we go. I have a cocos2d app, and there are targets that
I have an app that uses UIImage animation, and the timing of the animation
I'm making a game with cocos2d and I have a bunch of sprites that

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.