Game Development Reference
In-Depth Information
The button's position and anchor point should be 0x0. Change the preferred size types to
% and the values to 100x100 to enlarge the button to the
W#_l#
sprite's size. Then clear
the
Title
field and change the
Sprite frame
properties of the
Normal
and
Highlighted State
to
<NULL>
. This gives you the same invisible button as in the
MainMenuButtons.ccb
.
On the button's
Item Code Connections
tab, enter
shouldLoadLevel:
as the selector. Note
the trailing colon, because you'll want to receive the button as a parameter.
Now you can copy and paste the button eight times. Then drag one copy of the button so
that each
W#_l#
sprite has one button as a child.
Finally, you'll need a way to identify the buttons to know which level you should be load-
ing when a particular button is tapped. One way to do so is to use a consecutive number-
ing scheme by entering
1
as the name for the first button;
2
would be the name of the
second button, and so on until the last button, whose name should be 9. Be sure to enter
only digits, and don't pad with zeros. The name property will be the only property unique
to each button. The layout of the first page is given as an example in
Figure 8-6
.
The result can be seen in
Figure 8-7
,
which shows the first two pages of the
Scroll View
.
Figure 8-7
.
The final design of two Scroll View pages. Note the dimmed level buttons
Unlocking Levels
Before you can program the level-selection buttons, you'll have to update the
GameState
class to record which levels are unlocked and what the most recently played
level is.
Open
GameState.h
, and add the highlighted code of
Listing 8-5
.
Listing 8-5
.
Adding level properties to GameState
Search WWH ::
Custom Search