Hot to disable touch touch in CCLayer in cocos2d

I have a subclass of CCLayer that I use to display some sprites and show some animations. He also has CCMenu with some elements. When the user selects a menu item, I want to start the animation, and then show another scene. But I want the user to not be able to touch anything on the screen during the animation.

Of course, I can just turn off touch processing in my callbacks, but maybe there is an easier way - just turn off all touch manipulations for a while?

+3
source share
2 answers

You want to see the CCTouchDispatchersingleton class . If you add a target touch handler that swallows the touch (and does nothing), you will not get any touch. As far as I can tell, there is no way to completely disable the touch.

Alternatively, you can create a new CCLayer that on top of everything else (I think z order really high will do this) and let it know and it does nothing with a touch.

hope this helps.

0
source

Disable the touch manager before starting the animation and enable the touch manager after the animation stops. 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];
+3
source

Source: https://habr.com/ru/post/1784077/


All Articles