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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:12:14+00:00 2026-06-07T15:12:14+00:00

I am creating a toggle switch. I have a CCScene containing a CCLayer containing

  • 0

I am creating a toggle switch. I have a CCScene containing a CCLayer containing a ToggleNode. The ToggleNode shows properly with the sprites and labels I put in. The touch handling is not working because the ToggleNode’s bounding box seems to remain zero. I catch the touch in the CCLayer (which works as the ccTouchBegan:withEvent: is being entered) and there I have this code:

- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{
    CGPoint touchLocation = [self convertTouchToNodeSpace:touch];

    NSLog(@"bounding box: %f, %f, %f, %f", toggleNode.boundingBox.origin.x, toggleNode.boundingBox.origin.y, toggleNode.boundingBox.origin.x + toggleNode.boundingBox.size.width, toggleNode.boundingBox.origin.y + toggleNode.boundingBox.size.height);
    NSLog(@"touch: %f, %f", touchLocation.x, touchLocation.y);

    if (CGRectContainsPoint(toggleNode.boundingBox, touchLocation)) {
        [toggleNode toggle];
    }

    return NO;
}

A touch on the ToggleNode results in:

bounding box: 512.000000, 384.000000, 512.000000, 384.000000
touch: 508.000000, 378.000000

Which makes me believe the bounding box remains zero. But why? A retain problem? I am still learning in cocos2d but I do not think this is normal behavior.

  • 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-07T15:12:17+00:00Added an answer on June 7, 2026 at 3:12 pm

    If ToggleNode is derived from CCNode, this behavior is normal. A CCNode has a 0-sized bounding box and the contentSize property is also zero.

    If you derive your class from CCNode, it’s up to you to set the contentSize property (this also updates the bounding box) to whatever size it should have.

    Only if you use a class that use a texture (CCSprite, CCLabelTTF and others) does cocos2d set the contentSize by itself.

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

Sidebar

Related Questions

I'm creating a toggle switch with jquery but still don't understand how to trigger
I'm creating a custom on / off toggle switch for the iPhone (similar to
I am creating a custom toggle switch i all most done with the design
Creating a JApplet I have 2 Text Fields, a button and a Text Area.
I'm trying to create a vertical toggle switch control for the iPhone (along the
I am creating a simple custom control extending from toggle button that allows the
This is a snippet within a toggle() function. I have a header that when
So I have been creating a simple animation that copies a div, and expands
I'm creating a form, that needs to have examples in the input fields. So
I have a custom ListView Adapter , with which I'm creating rows for a

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.