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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T18:32:08+00:00 2026-06-03T18:32:08+00:00

I have a CCSprite (in which i have a b2body); The scope is to

  • 0

I have a CCSprite (in which i have a b2body); The scope is to create a sprite that moves with a body to a location and back;

I create the b2body in this way:

 if (_body) 
    {
        _world->DestroyBody(_body);
    }


    b2BodyDef bd;
    bd.type = b2_kinematicBody;


    _body = _world->CreateBody(&bd);

    b2PolygonShape shape;

    b2Vec2 _p1, _p2 , _p1sub,_p2sub;

    _p1 = b2Vec2(point1.x/PTM_RATIO,point1.y/PTM_RATIO);
    _p2 = b2Vec2(point2.x/PTM_RATIO,point2.y/PTM_RATIO);


    shape.SetAsEdge(_p1, _p2);
    _body->CreateFixture(&shape, 0);

After i created the body, i initialize the action:

id a1 = [CCMoveBy actionWithDuration:1 position:ccp(0,-self.position.y+destinationPoint.y)];
        id action2 = [CCRepeatForever actionWithAction:
                      [CCSequence actions: [[a1 copy] autorelease], [a1 reverse], nil]
                      ];
        [self runAction:action2];

on each frame, i update the body location

 _body->SetTransform(b2Vec2(self.position.x/PTM_RATIO,self.position.y/PTM_RATIO), 0);

The thing is that they are both drawn but the sprite is in the correct position while the body is not; the moves are coherent

FYI i use PTM_RATIO through out the game so this is surely not the problem

  • 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-03T18:32:15+00:00Added an answer on June 3, 2026 at 6:32 pm

    Keep in mind that the sprite’s position will be an offset to its parent’s position. If the parent is not a CCNode, CCScene or CCLayer (or their position is not 0,0) the sprite will be offset by the parent’s position.

    For example, a sprite (let’s call it S) with dimensions (contentSize) of 100,100 is located at position 0,0. Now you add a child node to S. The child node’s position (unless modified) will be at -50,-50 due to the fact that child nodes orient themselves on their parent’s lower left corner instead of the parent’s actual position. This frequently throws even the most experienced cocos2d programmers off guard.

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

Sidebar

Related Questions

I'm trying to create a extended CCSprite class that can detect touches. I have
I have multiple sprites placed onto a background sprite like this: //my background CCSprite
I have a Balloon class (see this ) that inherits from CCSprite . I
I have a sprite on which there is a label (CCLabelTTF). On that label
I have a CCSprite that has all its properties modified: rotation, scale, skewX, skewY,
have written this little class, which generates a UUID every time an object of
I am trying to have a CCSprite be the album artwork sprite for when
I have an array randomAlphabets which contains CCSprite objects. I need to start animation
My problem: I have created a parent sprite which rotates forever. I have created
I have a hierarchy like this: Scene  - gameWorld (CCLayer Z:0)     - player (CCSprite

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.