Game Development Reference
In-Depth Information
SettingsLayer
is loaded by
CCBReader
, using the full path to the
SettingsLayer.ccb
file. Then the
mainMenuButtons
reference is assigned, and the
settingsLayer
is
added as a child not to the
MainMenuButtons
class but to its parent (the
MainScene
instance). This is because the
MainMenuButtons
instance itself is set to
invis-
ible
—if the settings layer were a child of
MainMenuButtons
it, too, would be hid-
den. That would be counterproductive.
You can now run the game and tap the
Settings
button to open the settings popover. If you
move the sliders, you will see lines like the following (shortened) lines logged to the
Xcode Console:
[..] volume changed, sender: <CCSlider = 0x10a13ebf0 | Name
= musicSlider>
[..] volume changed, sender: <CCSlider = 0x10a135f70 | Name
= effectsSlider>
Each sender object is a different instance of
CCSlider
. If you gave the sliders a name on
the Item Properties tab, this name will also be logged.
Dismissing the Settings Popover
You can't currently dismiss the settings popover. You should fix that by introducing a gen-
eric close button. You can use the same button for other layers, and you can use the same
concept in general for buttons that should instead forward their selectors to a specific par-
ent class.
But in many cases, you can't do that because buttons and other
CCControl
nodes send
their selector to the document root—the CCB root node's custom class. Especially if the
Button
would be in its own CCB file, you would have to create a separate button for each
specific task—perhaps even separate buttons for the same task but different use cases.
There's a simple solution.
Right-click the
UserInterface
folder and select
New File
. Name the new document
CloseButton.ccb
and, for a change, use the
Node
type before clicking
Create
. With the
root node selected, switch to the
Item Code Connections
tab and set its custom class. Here
it should be named
CloseButton
.
Then drag a
Button
node from the Node Library View onto the stage. On the
Item Proper-
ties
tab, you need to change only the button's sprite frame for the normal state and the
Highlighted State
to
SpriteSheets/UserInterface/S_back.png
and change the
Background
Search WWH ::
Custom Search