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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:07:49+00:00 2026-05-26T15:07:49+00:00

In my Box2d game I found out that I must update my CCSprite position

  • 0

In my Box2d game I found out that I must update my CCSprite position in the game loop so it works properly. I have looked through the Box2D docs to see what APIs there are to get the b2Body coordinates but I didn’t see anything and this seems unclear.
Should I be moving each CCSprite manually or is there an easy way to move all CCSprite on screen to the b2Bodys associated with them?

Does anyone have any idea on how to do this?

Thanks!

Edit1:
Would this code just update every sprite in my world to the b2Body corresponding to them? And this will work with the x and y axis and rotation correct?

for(b2Body *b = _world->GetBodyList(); b; b=b->GetNext()) {
        if (b->GetUserData() != NULL) {
            CCSprite *sprite = (CCSprite *)b->GetUserData();

            b2Vec2 b2Position = b2Vec2(sprite.position.x/PTM_RATIO,
                                       sprite.position.y/PTM_RATIO);
            float32 b2Angle = -1 * CC_DEGREES_TO_RADIANS(sprite.rotation);

            b->SetTransform(b2Position, b2Angle);
        }
    }
  • 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-26T15:07:49+00:00Added an answer on May 26, 2026 at 3:07 pm

    simply do this:

    In your init class schedule the tick method like this

    [self schedule: @selector(tick:)];

    -(void)tick: (ccTime) dt
    
    
     for (b2Body* b = world->GetBodyList(); b; b = b->GetNext())
     {
         if (b->GetUserData() != NULL)
         {
             CCSprite *spr= (CCSprite*)b->GetUserData();
             CCSprite *myActor = (CCSprite*)b->GetUserData();
             myActor.position = CGPointMake( b->GetPosition().x * PTM_RATIO, b->GetPosition().y * PTM_RATIO);
             myActor.rotation = -1 * CC_RADIANS_TO_DEGREES(b->GetAngle());
         }
    

    }

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

Sidebar

Related Questions

In the box2d physics loop of my game (the step), I must call the
I have a main character in my Box2d game that has a b2PolygonShape collision.
I'm using Box2d for a Bike Physics Game, Box2d lets you have fixtures that
I am using Box2D with Cocos2D in my game. I am aware that Cocos2D
i am using box2d to developed iphone game.But i have not a lot of
I'm developing a physics game using AndEngine with box2d physics engine. I have a
I have a Box2D world which works great. I'm using it in a simple
I found that Chalk Ball has been developed with andengine and Box2D as physics
I am using Box2d and Cocos2d to develop an iPhone game. I have a
I'm trying to make a small game using both SFML and Box2D. 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.