Game Development Reference
In-Depth Information
precise: it may or may not work, depending on the device in debug configurations, but it
will certainly not work in release configurations.
Tip
I recommend adding an
NSAssert
line directly before the
addChild:
line to verify that
newMenuLayer
is not nil. The popover might be in a differ-
ent folder, there might be a typo in the CCB's name, or the popover CCB file
simply wasn't created or published yet. Those are common and often repeatedly
occuring issues, not just in this example game. It's a good idea to try and catch
those early.
Like the
_gameMenuLayer.gameScene
before, the
_popoverMenuLay-
er.gameScene
is assigned to
self
, to allow methods inside the
GameMenuLayer
class to send messages back to the
GameScene
instance.
When a popover menu is shown, the pause button and other static user interface elements
should be hidden. Setting the
_gameMenuLayer.visible
to
NO
effectively hides the
layer and thus the pause button, which in turn makes the button inactive. A button you
can't see is a button you can't touch, so to speak.
Pausing the
_levelNode
prevents the game from advancing by pausing all of the child
nodes of the
levelNode
. Pausing a node pauses its Timeline animations, running ac-
tions, and scheduled selectors. Because the
_physicsNode
is a child of the
_levelNode
, the physics world will also be paused.
In order to remove a popover menu, you also need to add the
removePopover
method
node from its parent (the
GameScene
node) and sets the
_popoverMenuLayer
ivar
to
nil
to allow a new popover to appear. Even though the
_popoverMenuLayer
should become
nil
automatically right away, it's a good idea to remind yourself that this
is intentional by explicitly assigning
nil
.
Listing 6-8
.
Removing a popover
-(void) removePopover
{
if (_popoverMenuLayer)
{
[_popoverMenuLayer removeFromParent];
Search WWH ::
Custom Search