Game Development Reference
In-Depth Information
Warning The lists of menu items always end with nil as the last parameter.
This is a technical requirement. If you forget to add nil as the last parameter,
your app will crash at that particular line.
It takes a fair bit of code to set up a menu. The first menu item is based on
CCMenuItemFont and simply displays a string. When the menu item is touched, it
calls the method menuItem1Touched . Internally, CCMenuItemFont simply cre-
ates a CCLabel . If you already have a CCLabel , you can use that with the
CCMenuItemLabel class instead.
Likewise, there are two menu item classes for images: one is CCMenuItemImage ,
which creates an image from a file and uses a CCSprite internally, and the other is
one I've used here, CCMenuItemSprite . This class takes existing sprites as input,
which I think is more convenient because you can use the same image and simply tint
its color to achieve a highlighting effect when touched.
CCMenuItemToggle accepts exactly two CCMenuItem -derived objects and, when
touched, toggles between the two items. You can use either text labels or images with
CCMenuItemToggle .
Finally, CCMenu itself is created and positioned. Because the menu items are all chil-
dren of CCMenu , they're positioned relative to the menu. To keep them from stacking
up on each other, you have to call one of CCMenu 's align methods, like alignItem-
sVerticallyWithPadding , as shown at the end of Listing 3-1 .
Because CCMenu is a node containing all menu items, you can use actions on the
menu to let it scroll in and out. This makes your menu screens appear less static, which
is usually a good thing. See the Essentials project for an example. In the mean-
time, take a look at Figure 3-9 to see what your current menu looks like.
Search Nedrilad ::

Custom Search