ios - how do you assign touches to two CCColorLayer? -


i have created 2 color layers , displayed them on 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 enable touches each layer, layer 1 , layer 2, example if user touches layer 1 (do something) , if touch layer 2 (do else). have set touch dispatcher,

-(void) registerwithtouchdispatcher {     [[cctouchdispatcher shareddispatcher] addtargeteddelegate:self priority:no swallowstouches:yes]; } 

after dont know do, tried search cocos2d documentation , couldnt find thanks!

if want them both registered touch dispatcher, need subclass them , add registerwithtouchdispatcher each subclass directly, use subclasses in master layer or scene.

this how register individual sprites own touches if don't want layer manage touches sprites.

when doing this, want set different priorities important layer has chance respond touch before other layer, don't same touch processed multiple layers.


Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -