* Assertion failure in -[CCTouchDispatcher forceAddHandler:array:], /libs/cocos2d/Platforms/iOS/CCTouchDispatcher.m:108
* Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Delegate already added to touch dispatcher.'
The line causing it is
skillsMenu.isTouchEnabled = YES;
skillsMenu
is just a CCMenu
. I like to enable/disable it with the above line often.
The problem is, I don't know how to interpret this error properly - I have no clue why would setting this property cause such error.
Perhaps it was wrong to use that line in the first place. Is there not a better way to enable/disable a CCMenu
?
cocos2d-iphone 1.0.1
isTouchEnabled
registers/unregisters the touch handler for the object.
Registering and unregistering of touch handlers in the same step has caused problems in the past, although, in more recent versions, I believe this has been fixed.
In any case, if you simply want to temporarily enable/disable a menu, it will be less problematic to enable/disable the individual menu items:
-(void) modifyMenu:(CCMenu*) menu withEnabledValue:(BOOL) enabled
{
CCMenuItem *menuItem;
CCARRAY_FOREACH(menu.children, menuItem)
{
[menuItem setIsEnabled: enabled ];
}
}
CCMenu has an a .enabled property (setable), use that instead. The difference with isTouchEnabled is that the menu is not registered/deregistered from the touch dispatcher. Instead, when myMenu.enabled is false, the touches are simply ignored from the start in CCMenu's ccTouchBegan delegate method. This is cleaner, and avoids the trap of playing with isTouchEnabled (that is a property of the CCLayer class, which CCMenu extends).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With