Game Development Reference
In-Depth Information
__weak MainMenuLevelSelect* _levelSelect;
}
-(void) didLoadFromCCB
{
_levelSelect = (MainMenuLevelSelect*)[self.parent
getChildByName:@"levelSelect"
recursively:YES];
_levelSelect.parent.visible = NO;
_levelSelect.mainMenuButtons = self;
}
// ... remaining methods omitted
This imports the new MainMenuLevelSelect class header in order to add an ivar for
that class named _levelSelect . So far, so good.
In didLoadFromCCB , you obtain the reference to the MainMenuLevelSelect in-
stance by its name. You've done that a couple times before. But wait, the
MainMenuButtons class has no relation to the Scroll View or the Scroll View 's Content
node, meaning they aren't children of the MainMenuButtons class. If you take a closer
look at the getChildByName: method, you'll notice it is actually sent to the
MainMenuButtons parent node. Since MainMenuButtons is a child of the MainS-
cene node, self.parent is a reference to the MainScene instance. The MainS-
cene contains the Scroll View as a child, and the Scroll View contains the Content node
as a child. Therefore, the MainMenuLevelSelect instance can be found by its name
recursively.
In the same light, _levelSelect.parent.visible = NO hides the
CCScrollView because it is the parent of the MainMenuLevelSelect instance. It
is important to hide the CCScrollView instance rather than the
MainMenuLevelSelect instance because this will disable all touch events for the
CCScrollView . If you only made _levelSelect invisible, it has the same effect
visually, but the user could still swipe through the various pages unknowingly. Since the
CCScrollView is always made invisible, you can optionally select the Scroll View
node in MainScene.ccb and uncheck its Visible property to hide it.
Last, the _levelSelect is assigned a reference to the MainMenuButtons instance
so that it can later send the show message to the MainMenuButtons instance when the
user closes the MainMenuLevelSelect popover.
Search WWH ::




Custom Search