Game Development Reference
In-Depth Information
Set
Title
to
Restart
,
Exit
, or
Resume
, depending on which button you are
editing.
Change
Sprite frame
for both
Normal State
and
Highlighted State
to the
same image. You may want to use the following images from
SpriteSheets/
UserInterface
:
P_restart.png
,
P_exit.png
,
P_resume.png
.
For
Highlighted State
, change both
Background color
and
Label color
to a
gray color—for instance, the web color with hex code
#999999
. This will
give a visual cue when touching the buttons: they will appear darker while
highlighted.
Under the
CCLabelTTF
section, edit the
Font name
and
Font size
as you
like. You may need to increase
Horizontal padding
, perhaps even
Vertical
padding
, to make the background image slightly larger so that the button's
text is wholly contained in the background frame.
After editing the properties, switch to the
Item Code Connections
tab. For each button,
enter the corresponding
Selector
:
shouldRestartGame
,
shouldExitGame
, and
shouldResumeGame
.
You can publish, build, and run the project now. Then tap the pause button to see your
new popover menu. Note that tapping any button on the layer will cause a crash at this
stage.
If nodes aren't where they are supposed to be, verify the parent-child relationship is cor-
rect and that position types are set to
%
for all nodes. See
Figure 6-6
for reference.
Interlude: Full-Screen Popovers
An in-game menu that only temporarily replaces the current scene is a frequent request,
and developers are often left wondering how to implement that.
Usually, developers are seeking to use push and pop scene methods, or even replace
scenes while saving and restoring game states. While there's use for both, it's really
simple to create a nondestructive full-screen “scene” on top of the current scene without
having to change scenes. You can do that with minor enhancements to the popover layer
you've just created. Let's try it.
Drag and drop a
Color Node
from the
Node Library View
onto the
PauseMenuLayer.ccb
stage. Move the color node in the Timeline so that it is above the
P_bg
background sprite.
Be sure the color node is not a child of the background sprite. Then set the color node's
Search WWH ::
Custom Search