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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:29:54+00:00 2026-06-02T00:29:54+00:00

I have a CCLayer subclass MyLayer in which I handle touch events: (BOOL) ccTouchBegan:(UITouch

  • 0

I have a CCLayer subclass MyLayer in which I handle touch events:

(BOOL) ccTouchBegan:(UITouch *) touch withEvent:(UIEvent *) event

I set the content size of MyLayer instances like this:

`myLayer.contentSize = CGSizeMake(30.0, 30.0);`

I then add MyLayer instances as children of ParentLayer. For some reason I can tap anywhere on the screen and a MyLayer instance will detect the tap. I want to only detect taps on the visible portion/content size. How can I do this?

Are the MyLayer instances somehow inheriting a “tappable area” from somewhere else? I’ve verified that the contentSize of the instance just tapped is (30, 30) as expected. Perhaps the contentSize isn’t the way to specify the tappable area of CCLayer subclass.

  • 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-02T00:29:55+00:00Added an answer on June 2, 2026 at 12:29 am

    When the touch is enabled on a particular CCLayer, it receives all of the touch events in the window. That being said, if there are multiple layers, all layers will receive the same touches.

    To alleviate this, obtain the location from the UITouch, convert it to Cocos2d coordinates, then check to see if it is within the bounds of the Layer you are concerned with.

    Here’s some code to work with:

    CCLayer * ccl = [[CCLayer alloc] init];
    CGPoint location = [touch locationInView:[touch view]];
    location = [[CCDirector sharedDirector] convertToGL:location];
    if (CGRectContainsPoint(CGRectMake(ccl.position.x - ccl.contentSize.width/2, ccl.position.y - ccl.contentSize.height/2, ccl.contentSize.width, ccl.contentSize.height), location)) {
       //continue from there...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a scene created like that: MyScene (subclass of CClayer) .m +(CCScene *)
I am trying to have my subclass of CCLayer respond to multitouch. In the
I have a class which is a subclass of UIView . I am able
I have a CCLayer which I need to add a camera to, on top
I have a UIView subclass that moved around 'event's when the user touches them,
I have a layer-hosting view set up like this in a custom NSView subclass:
I have a UIView subclass which seeks to create a rounded rect overlay on
i have a CCLayer class on top of which i am adding another CClayer
I have a UITableViewCell subclass with backgroundView set to my own UIView object. This
I have a custom button which is my own subclass of UIButton . It

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.