Game Development Reference
In-Depth Information
// align label to the bottom
label.anchorPoint = CGPointMake(0.5f, 0);
// use case: place label at top-right corner of the screen
// the label's text extends to the left and down and is always completely on screen
CGSize size = [[CCDirector sharedDirector] winSize];
label.position = CGPointMake(size.width, size.height);
label.anchorPoint = CGPointMake(1, 1);
Menus
You'll soon need some kind of button a user can click to perform an action, such as go-
ing to another scene or toggling music on and off. This is where the CCMenu class
comes into play. CCMenu is a subclass of CCLayer and accepts only CCMenuItem
nodes as children. You can see the CCMenuItem class hierarchy in Figure 3-5 and in
Figure 3-8 for the sake of clarity.
Figure 3-8 . The CCMenuItem class hierarchy
Listing 3-1 shows the code for setting up a menu. You can find the menu code in the
Essentials project in the MenuScene class.
Listing 3-1. Creating Menus in cocos2d with Text and Image Menu Items
CGSize size = [CCDirector sharedDirector].winSize;
// set CCMenuItemFont default properties
 
 
 
 
Search Nedrilad ::




Custom Search