0

I am using cocos2d 2.1 version to code up a simple board game on iOS. The logic requires disabling touch detection on individual layers for a predefined period of time. While disabling touch detection on individual layers works just fine I am having a lot problems re-enabling the touch detection.

I disable the touch detection using touchEnabled property

layer.touchEnabled = NO;

I try later to reverse this using the same property

layer.touchEnabled = YES;

But this does not seem to work at all and none of the tap events are any longer propagated to the layer..

What am I doing wrong here? Is there something I am missing??

Franek Kuciapa
  • 141
  • 1
  • 8
  • Problem resolved. It turns out I needed to set the touchMode to kCCTouchesOneByOne in the initializer of my layer before setting initial touchEnabled to YES. Otherwise, wrong dispatcher was getting installed inside CCLayer and was messing things up. I needed the one with swallowing touches set to YES. – Franek Kuciapa Feb 24 '14 at 12:35
  • If you've resolved the issue, trying answering your own question and marking it as the solution. – Reza Shirazian Feb 27 '14 at 01:25

2 Answers2

0

you have to give dispatcher delegate again, this may help you

-(void)touchActive
{
    if (self.touchEnabled)
    {
        return;
    }

    [[[CCDirector sharedDirector] touchDispatcher] addTargetedDelegate:self
                                                          priority:0
                                                   swallowsTouches:YES];
    self.touchEnabled = YES;

}
mohitdream4u
  • 166
  • 10
0

Resolved.

It turns out I needed to set the touchMode to kCCTouchesOneByOne in the initializer of my layer before setting initial touchEnabled to YES. Otherwise, wrong dispatcher was getting installed inside CCLayer and was messing things up. I needed the one with swallowing touches set to YES.

layer.touchMode = kCCTouchesOneByOne;
layer.touchEnabled = YES;
Franek Kuciapa
  • 141
  • 1
  • 8
  • There is also another possibility. Now, you probably use '-(BOOL)ccTouchBegan'. If you would have only enabled touch, you could have used '-(void)ccTouchesBegan' for handling touch events. – iajheyst Apr 28 '14 at 14:03