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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:23:19+00:00 2026-06-10T09:23:19+00:00

As a follow-on question to my previous question about displaying the anchor point ,

  • 0

As a follow-on question to my previous question about displaying the anchor point, I subclassed CCSprite and changed its draw method as follows:

[super draw];
ccDrawColor4F(0, 1, 0, 1);
ccDrawCircle(self.anchorPointInPoints, 20, 0, 8, YES);

This works great. For extra credit, I added the following to display its bounding box:

CGRect bb = self.boundingBox;
CGPoint vertices[4] = {
    [self convertToNodeSpace:ccp(bb.origin.x, bb.origin.y)],
    [self convertToNodeSpace:ccp(bb.origin.x + bb.size.width, bb.origin.y)],
    [self convertToNodeSpace:ccp(bb.origin.x + bb.size.width, bb.origin.y + bb.size.height)],
    [self convertToNodeSpace:ccp(bb.origin.x, bb.origin.y + bb.size.height)],
};
ccDrawPoly(vertices, 4, YES);

This also works great, until I reparent a sprite:

CGPoint oldPosition = [sprite convertToWorldSpace:sprite.position];
[sprite removeFromParentAndCleanup:NO];
[parentSprite addChild:sprite];
sprite.position = [sprite convertToNodeSpace:oldPosition];

The sprite’s now in the proper position and its anchor point draws where it should, but the bounding box draws in the wrong place. What am I doing wrong?

  • 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-10T09:23:20+00:00Added an answer on June 10, 2026 at 9:23 am

    Bounding box of a node is relative to its parent. Drawing done in draw method is in node’s local space. convertToNodeSpace: converts coordinates from world space to local space, not from parent’s space.

    When you reparent node to a parent with different origin while maintaining same “world” position of this node, origin of its bounding box changes.

    Your mistake is that you treat your sprite’s bounding box as if its coordinates were in world space.

    Second, you don’t need to do the convert-to-x-space dance to draw bounding box of a sprite. Open ccConfig.h file in cocos2d folder of your project and change

    #define CC_SPRITE_DEBUG_DRAW 0
    

    line to

    #define CC_SPRITE_DEBUG_DRAW 1
    

    Third, coordinates of sprite.position point are relative to its parent, not to the sprite. When you call [node convertToWorldSpace:aPoint], it will treat aPoint as if it were in node’s local space. If you want to get world coordinates of a node’s position, you should call convertToWorldSpace: on node’s parent: [node.parent convertToWorldSpace:node.position].

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

Sidebar

Related Questions

As a follow up to my previous question about REST URIs for retrieving statistical
This is a follow up question to a previous question I asked about calculating
This is a follow on from my previous question although this is about something
To follow from my previous question about virtual and multiple inheritance (in a cross
This is a follow-up to my previous question about developing Perl applications . Let’s
This is a follow up to a previous question that I had before about
This follows my previous question about TFS 2010 and the possibility to create a
This follows on from my previous question about Moose structured types. I apologise for
This is a follow up to my previous question (about an old top coder
This is a follow up to a previous question I asked about how to

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.