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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:03:51+00:00 2026-06-14T05:03:51+00:00

My environment is iPhone with Cocos2d. I’m trying to move a player in a

  • 0

My environment is iPhone with Cocos2d.

I’m trying to move a player in a game a single step forward with a sprite animation although I’m not sure of the correct way to do this.

First of all for reference here’s part of my init method which loads the animations into a NSDictionary for later user.

-(id) init
{
if( (self=[super init]) ) {
    ..
    ..
    NSMutableArray *walkUpFrames = [NSMutableArray array];
    [walkUpFrames addObject: [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"player01.png"]];
    [walkUpFrames addObject: [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"player02.png"]];
    [walkUpFrames addObject: [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"player03.png"]];
    NSMutableArray *walkDownFrames = [NSMutableArray array];
    [walkDownFrames addObject: [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"player04.png"]];
    [walkDownFrames addObject: [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"player05.png"]];
    [walkDownFrames addObject: [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"player06.png"]];
    NSMutableArray *walkLeftFrames = [NSMutableArray array];
    [walkLeftFrames addObject: [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"player07.png"]];
    [walkLeftFrames addObject: [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"player08.png"]];
    [walkLeftFrames addObject: [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"player09.png"]];
    NSMutableArray *walkRightFrames = [NSMutableArray array];
    [walkRightFrames addObject: [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"player10.png"]];
    [walkRightFrames addObject: [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"player11.png"]];
    [walkRightFrames addObject: [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"player12.png"]];

    self.walkingFrames = [NSDictionary dictionaryWithObjectsAndKeys:
                          walkUpFrames, @"up",
                          walkDownFrames, @"down",
                          walkLeftFrames, @"left",
                          walkRightFrames, @"right",
                          nil];
    ......
}
return self;
}

First I tried this code to move the player which successfully moves the sprite to the new position and runs the animation but the sprite gets to the position instantly and then runs the animation which is no good.

-(void)setPlayerPosition:(CGPoint)position {

  CCAnimation *walkAnim = [CCAnimation animationWithFrames:[self.walkingFrames valueForKey:@"right"] delay:0.05 ];
  self.walkAction = [CCAnimate actionWithAnimation: walkAnim restoreOriginalFrame:YES];

  [_player runAction:_walkAction];
  _player.position = position;
}

I’m guessing I’m suppose to use CCMoveTo but I don’t see how to use it with animationWithFrames. Any ideas? (please provide code example)

-(void)setPlayerPosition:(CGPoint)position {

 self.walkAction = [CCMoveTo actionWithDuration:0.1 position:position];

 [_player runAction:_walkAction];

}

Thanks for any replies.

  • 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-14T05:03:52+00:00Added an answer on June 14, 2026 at 5:03 am

    Running multiple actions did the trick. Thanks Morion….

    -(void)setPlayerPosition:(CGPoint)position
    {
        CCAnimation *walkAnim = [CCAnimation animationWithFrames:[self.walkingFrames valueForKey:@"right"] delay:0.1 ];
        [_player runAction:[CCAnimate actionWithAnimation: walkAnim restoreOriginalFrame:YES]];
    
        [_player runAction:[CCMoveTo actionWithDuration:0.3 position:position]];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a development environment that runs directly on an the iPhone OS? I
Apple doesn't want anyone to create iPhone apps outside of the Xcode/Objective-C environment. How
I had a fully working build environment before upgrading to iPhone OS 3.1 and
I'm running automated application unit tests under a C.I. environment for iPhone apps and
I want to develop my iPhone app but I am not sure what could
I have an iPhone app that I'm trying to run on my phone via
I am developing application for iPhone environment for 1 year from now,In a recent
I am new to iPhone/iOS environment, on the Mac I could see the system
im trying to port an iphone app to android. i am completely new to
So I took the step upgrading to Xcode 3.2.5 (iPhone SDK 4.2) and now

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.