Game Development Reference
In-Depth Information
11.
For both
Normal State
and
Highlighted State
, change the
Sprite frame
property to the
<NULL>
item. This removes the button's background im-
ages. It is now an invisible button.
12.
The size of the button will be a bit too small. Change the button's
Pre-
ferred size
property to 60x60.
You now have two invisible buttons on both the
play
and
settings
sprites. The fact that the
buttons rotate along with the sprites won't matter much since the buttons are square and
cover the sprite's circular-shaped images well enough, regardless of rotation. Though you
could, of course, apply the same reverse-animation trick you used for the sprite's labels.
Connecting the Buttons
To connect the buttons with selectors, switch to the
Item Code Connections
tab. Then se-
lect each button in order and, in the Selector field, enter
shouldPlayGame
for the play
button and
shouldShowSettings
for the settings button.
There's one more thing missing though. The selectors need to be sent somewhere, and that
somewhere is the
Document root
. This term refers to the root node of the
MainMenuBut-
tons.ccb
. Select its root node, and enter
MainMenuButtons
in the
Custom class
field.
Now open the Xcode project and add a new Objective-C class. Do so as described in
it should be a subclass of
CCNode
.
Edit the
MainMenuButtons.m
file to add the methods in
Listing 7-2
.
Listing 7-2
.
Testing that the button selectors work
#import "MainMenuButtons.h"
@implementation MainMenuButtons
-(void) shouldPlayGame
{
NSLog(@"PLAY");
}
-(void) shouldShowSettings
{
NSLog(@"SETTINGSā);
}
@end
Search WWH ::
Custom Search