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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:31:45+00:00 2026-06-08T06:31:45+00:00

I animate my character like that : -(void) createHero { _batchNode = [CCSpriteBatchNode batchNodeWithFile:@Snipe1.png];

  • 0

I animate my character like that :

-(void) createHero
{


    _batchNode = [CCSpriteBatchNode batchNodeWithFile:@"Snipe1.png"];
    [self addChild:_batchNode];
    [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"Snipe1.plist"];

    //gather list of frames
    NSMutableArray *runAnimFrames = [NSMutableArray array];
    for(int i = 1; i <= 7; ++i) 
    {
        [runAnimFrames addObject:
        [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
        [NSString stringWithFormat:@"run000%d.png", i]]];
    }

    //create sprite and run the hero
    self.hero = [CCSprite spriteWithSpriteFrameName:@"run0001.png"];
    _hero.anchorPoint = CGPointZero;
    _hero.position = self.heroRunningPosition;

    //create the animation object
    CCAnimation *runAnim = [CCAnimation animationWithFrames:runAnimFrames delay:1/30.0f];
    self.runAction = [CCRepeatForever actionWithAction: [CCAnimate actionWithAnimation:runAnim restoreOriginalFrame:YES]];

    [_hero runAction:_runAction];
    [_batchNode addChild:_hero z:0];
}

This works fine an my character is running, but now i want a second animation when he jumps. At the moment i make it like that:

-(void)changeHeroImageDuringJump 
{
    [_hero setTextureRect:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"run0007.png"].rect]; 
}

But now i want a second plist with a second png, so i get a whole new animation when the character jumps. How can i implement that ?

  • 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-08T06:31:46+00:00Added an answer on June 8, 2026 at 6:31 am

    In my case, i implemented an AnimatedSprite class that will handle this for me. This way, I add files like so:

    NSDictionary* anims = [NSDictionary dictionaryWithObjectsAndKeys:
            @"Animations/Character/idle_anim.plist", @"Idle",
            @"Animations/Character/walk_anim.plist", @"Walk",
            @"Animations/Character/run_anim.plist",    @"Run", nil];
    
    CCNode* myNode = [[AnimatedSprite alloc] initWithDictionary:anims 
                          spriteFrameName: @"character_idle_01.png"
                            startingIndex:@"Idle"];
    

    Changing the animation is as simple as:

    [myNode setAnimation: @"Run"];
    

    Heres my implementation This is the .h

    @interface AnimatedSprite : CCSprite
    {
        NSMutableDictionary* _spriteAnimations;
        CCAction* _currentAnimation;
        NSString* _currentAnimationName;
        bool _initialized;
    }
    - (id) initWithTextureName:(NSString*) textureName;
    - (id) initWithArray: (NSArray*) animList spriteFrameName: (NSString*) startingSprite startingIndex: (int)startingIndex;
    - (id) initWithDictionary:(NSDictionary *)anims spriteFrameName:(NSString *)startingSprite startingIndex:(NSString *)startingAnim;
    
    - (void) addAnimation: (NSString*) animationName andFilename: (NSString*) plistAnim;
    
    - (void) setAnimationIndex: (int) index;
    - (void) setAnimation: (NSString*) animationName;
    @end
    

    And this is the .m

    #import "AKHelpers.h"
    
    @implementation AnimatedSprite
    
    NSMutableDictionary* _spriteAnimations;
    
    - (id) initWithTextureName:(NSString*) textureName
    {
        CCTexture2D* texture = [[CCTextureCache sharedTextureCache] addImage:textureName];
        CCSpriteFrame* frame = [CCSpriteFrame frameWithTexture:texture rect: CGRectMake(0, 0, 1, 1)];
    
        if ((self=[super initWithSpriteFrame:frame]))
        {
            _currentAnimationName = nil;
            _currentAnimation = nil;
            _spriteAnimations = [[NSMutableDictionary alloc] init ];
            _initialized = true;
    
        }
        return self;
    }
    - (id) initWithArray: (NSArray*) animList spriteFrameName: (NSString*) startingSprite startingIndex: (int)startingIndex
    {
        _initialized = false;
        _spriteAnimations = [[NSMutableDictionary alloc] init];
    
        // Add animations as numbers from 0 to animList.count
        int i = 0;
        for (NSString* anim in animList)
        {
            [self addAnimation: [NSString stringWithFormat:@"%d", i] andFilename:anim];
            i++;
        }
    
        if ((self = [super initWithSpriteFrameName:startingSprite]))
        {
            _currentAnimationName = nil;
            _currentAnimation = nil;
            [self setAnimationIndex: startingIndex];  
            _initialized = true;  
        }
    
        return self;
    }
    
    - (id) initWithDictionary:(NSDictionary *)anims spriteFrameName:(NSString *)startingSprite startingIndex:(NSString *)startingAnim
    {
        _initialized = false;
        _spriteAnimations = [[NSMutableDictionary alloc] init];//[[NSMutableArray alloc] init];
    
        // Add animations
        for (NSString* key in anims)
        {
            [self addAnimation: key andFilename: [anims objectForKey: key] ];
        }
    
        if ((self = [super initWithSpriteFrameName:startingSprite]))
        {
            _currentAnimationName = nil;
            _currentAnimation = nil;
            [self setAnimation: startingAnim];
            _initialized = true;
    
        }
        return self;
    }
    - (void) dealloc
    {
        [_currentAnimationName release];
        [_spriteAnimations release];
        [super dealloc];
    }
    
    - (void) setAnimation: (NSString*) animationName
    {
        if (![_currentAnimationName isEqualToString:animationName])
        {
            [_currentAnimationName release];
            _currentAnimationName = [animationName copy];
    
            // Stop current animation
            if (_currentAnimation != nil)
                [self stopAction:_currentAnimation];
            //[self stopAllActions];
    
            // Apply animation
            NSDictionary* clip = [_spriteAnimations objectForKey: animationName];
            if (clip)
            {
                _currentAnimation = [AKHelpers actionForAnimationClip:clip];
                if (_currentAnimation)
                    [self runAction:_currentAnimation];
            }
            else
            {
                _currentAnimation = nil;
            }
        }
    }
    
    - (void) setAnimationIndex: (int) index
    {
        [self setAnimation: [NSString stringWithFormat:@"%d", index]];
    }
    
    - (void) addAnimation: (NSString*) animationName andFilename: (NSString*) plistAnim
    {
        NSDictionary *clip = [AKHelpers animationClipFromPlist:plistAnim];
    
        if (clip)
        {
            [_spriteAnimations setObject:clip forKey:animationName];        
    
            if (_initialized && [_spriteAnimations count] == 1)
            {
                [self setAnimation:animationName];
            }
        }
    }
    
    @end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I load my animated character with a huge texture this way: [[CCSpriteFrameCache sharedSpriteFrameCache]addSpriteFramesWithFile:@MyFile.plist]; And
I would like to animate a 40x20 block of characters that I am cout
I am looking to animate a 3D character in WPF, imported from software like
I have some 3D character model, and I would like to animate them, to
I am looking to animate a LinearLayout of mine. I would like to make
I need to animate my background which have 6 images and that needed to
I'm trying to animate a logo. The markup looks like this: <div id=logo> <h1>
How would I animate individual characters of text on a page in HTML5. Like
I have two divs which I want to animate: <div id="character"> <div id="sprite"></div> </div>
I'd like to have an animated character on the page, with different animations for

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.