Game Development Reference
In-Depth Information
This code is just to test that the buttons work. If you run the app and tap the buttons,
you'll see the preceding NSLog statements printed to the Xcode console.
Settings Menu
The settings menu will be implemented as a popover, much like the pause and game over
menus of the game. There are several notable new features here. One is a universal close
button that closes the overlay it is added to by simply removing the corresponding parent
node. To ease creating the settings menu layout, the Box Layout node is used to arrange
the nodes in rows and columns.
Another feature is the Slider controls, and I'll describe how they can be used to change a
property's value—in this case, audio volume levels. Because the audio volumes should be
persisted across app launches, the GameState singleton class is introduced at the end of
this chapter.
Designing the Settings Menu with Box Layout
Right-click the UserInterface folder, select New File to create a new CCB document
named SettingsLayer.ccb of type Layer with the default size of 568x384. Start by chan-
ging the root node's Content size types to % for the layer to shrink and expand with its
parent node's size and, thus, the screen size. The content size width and height values
should be 100, 100.
As you have so frequently done before, drag a Node from the Node Library View onto the
stage, change its position type to % , and position values to 50 . Then rename the node to
settingsLayer . This node will act as the screen-centering container node for the rest
of the items.
From the UserInterface section in the Tileless Editor View, drag the S_bg image onto the
settingsLayer node . Alternatively, drag a sprite node from the Node Library View and
change its Sprite frame to S_bg.png . The new sprite must be a child node of settingsLayer .
It should automatically center on the stage.
Introducing Box Layout Nodes
Now for the Box Layout node. It can position nodes in either a horizontal or vertical lay-
out, meaning the nodes will either be stacked vertically or aligned horizontally. The set-
Search WWH ::




Custom Search