3

I've got a CCLayer subclass i'm using to display some sprites and to show some animations. Also it has a CCMenu with some items. When user selects some of the menu item i want to run an animation and then to show another scene. But i want user not to be able to touch anything on the screen while animation is running.

Of course, i can just disable handling touches in my callbacks, but maybe there is more simple way - just to disable all touch handling for a while ?

Andrew
  • 24,218
  • 13
  • 61
  • 90
  • You may want to look at this answer: http://stackoverflow.com/questions/1101965/how-can-i-disable-the-touch-detection – lorenzo Jan 28 '13 at 09:14

2 Answers2

3

Disable touch dispatcher before animation running and enable touch dispatcher after animation stopped. Here is the code snippet:

[[CCDirector sharedDirector] touchDispatcher].dispatchEvents = NO;
CCAnimation* animation = [CCAnimation animationWithFrame:@"numberexplode" frameCount:5 delay:0.2];
CCAnimate* animate = [CCAnimate actionWithAnimation:animation];
CCCallBlock* completion = [CCCallBlock actionWithBlock:^{
    [[CCDirector sharedDirector] touchDispatcher].dispatchEvents = YES;
}];
CCSequence* sequence = [CCSequence actions:animate, completion, nil];
[self runAction:sequence];
Gong Pengjun
  • 971
  • 7
  • 14
0

You want to look at the CCTouchDispatcher singleton class. If you add a targeted touch handler that swallows touches (and does nothing) then you won't get any touches handled. As far as I can tell there's no way to totally disable touches.

Alternatively you can make a new CCLayer that's on top of everything else (I think z order really high will do this), and make it clear, and have it do nothing with touches.

hope that helps.

slycrel
  • 4,275
  • 2
  • 30
  • 30