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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:03:03+00:00 2026-05-31T02:03:03+00:00

i have created two color layers and displayed them on the screen: if( (self=[super

  • 0

i have created two color layers and displayed them on the screen:

if( (self=[super init] )) {


        self.isTouchEnabled = YES;
        CGSize s = [[CCDirector sharedDirector] winSize];
        CCLayerColor* layer1 = [CCLayerColor layerWithColor: ccc4(255, 255, 0, 80)
                                                 width: 100 
                                                height: 300];
        layer1.position = ccp(s.width/3, s.height/2);
        layer1.isRelativeAnchorPoint = YES;
        [self addChild: layer1 z:1];

        CCLayerColor* layer2 = [CCLayerColor layerWithColor: ccc4(0, 0, 255, 255)
                                                 width: 100 
                                                height: 300];
        layer2.position = ccp((s.width/3)*2, s.height/2);
        layer2.isRelativeAnchorPoint = YES;
        [self addChild: layer2 z:1];

         }
       return self;

     }

i want to to enable touches for each layer, layer 1 and layer 2, for example if the user touches layer 1 (do something) and if you touch layer 2 (do something else). i have set up the touch dispatcher,

-(void) registerWithTouchDispatcher
{
    [[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:No swallowsTouches:YES];
}

after that i dont know what to do, i tried to search the cocos2d documentation and couldnt find anything thanks!

  • 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-31T02:03:05+00:00Added an answer on May 31, 2026 at 2:03 am

    If you want them to both be registered with touch dispatcher, you will need to subclass them and add the registerWithtouchDispatcher to each subclass directly, then use the subclasses in your master layer or scene.

    This is also how you register individual sprites with their own touches if you don’t want the layer to manage the touches for all its sprites.

    When doing this, you will want to set different priorities so the most important layer has a chance to respond to a touch before the other layer, so you don’t get the same touch processed by multiple layers.

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

Sidebar

Related Questions

I have created an animation chain I have two problems: The init function it
I have created a UserControl with two dependency properties: Value and Color. The Color
I have created two forms in my Windows Application. One Form acts as a
I have created two files: tunables.h #ifndef TUNABLES_H #define TUNABLES_H void tunables_load_conservative(); void tunables_load_aggressive();
I have created two JavaScript files. One file is "validators.js" and the other is
Let's say I have created two objects from class foo and now want to
I'm having a problem with mixing managed and unmanaged code. I have created two
I have created an item swapper control consisting in two listboxes and some buttons
I have created an alert view with two buttons using the following code: UIAlertView
@Solved The two subquestions I have created have been solved (yay for splitting this

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.