in General

Recursive disabling of CCNodes

This is an update of my previous post where I was attempting to lock/disable a CCScrollLayer when I launch a modal pop-up dialog.

The previous code doesn’t always work, and I’ve changed it a bit to the below;

It isn’t 100% perfect but it is a bit more recursive than the last version.

Basically the idea is:

  1. I want to disable/enable every node except my CoverLayer and her children, this is implicit because all the pop-up dialog’s appear as a child of CoverLayer
  2. I want to stop all interaction on CCScrollLayers
  3. I want to stop the user from clicking on a MenuItem within the CCScrollLayer multiple times

Again, it isn’t perfect; but its a start.

Put this in where you need to disable stuff; I put it in a singleton or a single controller instance and launch it there.


// Disabled/Enable layers
-(void) MenuStatus:(BOOL)_enable Node:(id)_node
{
BOOL showLogs = YES;

for (id result in ((CCNode *)_node).children)
{
if (showLogs == YES) NSLog(@"Node result = %@", [result class]);

if ([result isKindOfClass:[CoverLayer class]])
{
// Do nothing
if (showLogs == YES) NSLog(@" -- Do nothing --");

} else {

// Scrolllayer
if ([result isKindOfClass:[CCScrollLayer class]]) {
if (showLogs == YES) NSLog(@"A. Found CCScrollLayer...");
((CCScrollLayer *)result).isTouchEnabled = _enable;
[self MenuStatus:_enable Node:result];

} // end if

// Layers
if ([result isKindOfClass:[CCLayer class]]) {
if (showLogs == YES) NSLog(@"B. Found CCLayer -- %@", [CCLayer class]);

// Disable CCLayer and any children?
((CCLayer *)result).isTouchEnabled = _enable;

for (id result2 in ((CCLayer *)result).children)
{
if (showLogs==YES) NSLog(@" 1. child found: %@", [result2 class]);
[self MenuStatus:_enable Node:result2];
} // next
} // end if

// Menus
if ([result isKindOfClass:[CCMenu class]]) {
((CCMenu *)result).isTouchEnabled = _enable;
} // end if

} // end if

} // next

NSLog(@"-------------");
}