Game Development Reference
In-Depth Information
What remains is to update the shouldPlayGame method to the version in Listing 8-4 .
Listing 8-4 . Showing the level-selection popover
-(void) shouldPlayGame
{
_levelSelect.parent.visible = YES;
self.visible = NO;
}
This makes the CCScrollView visible and hides the MainMenuButtons instance.
Notice that, unlike with the SettingsLayer , the CCScrollView instance is not re-
moved from the scene and reloaded when it should be shown; rather, you simply change
its visible state on and off. Changing visible state is a lot more efficient if you need a giv-
en node (or branch of nodes) frequently compared to loading a CCB or even just creating
new node instances programmatically. Of course, changing visible states will not free
memory. But, again, if you need a node frequently, you have to have enough spare
memory to be able to show it at any time, so such nodes also can stay in memory the
whole time.
Furthermore, it often requires additional memory to create or load a node during the pro-
cess of loading or creating it. Specifically, when loading textures it is common that, for
just a frame or two, the memory usage increases twofold and immediately drops back
down to what the texture really uses. When your app is getting very close to receiving
memory warnings, it is better to not remove nodes that you are going to need frequently.
That said, the real reason to keep the CCScrollView and its Content node in the scene
for the entire time is a pragmatic one. You would have to create an additional CCB file
that contains just the Scroll View node in order to be able to load the Scroll View and its
Content node with CCBReader . At the moment, only the MainMenuLevelSelect.ccb (the
Scroll View 's Content node) is a separate CCB instance while the Scroll View node was
added directly to MainScene.ccb . So you would be able to load only the
MainMenuLevelSelect.ccb Content node with CCBReader .
If you were to remove the CCScrollView from its parent node, you would have to cre-
ate another instance of the CCScrollView programmatically, initializing it with a Con-
tent node loaded with CCBReader or assigning it to the Scroll View 's contentNode
property—but only the second time and every time after that, further complicating the
code.
Search WWH ::




Custom Search