Game Development Reference
In-Depth Information
Figure 2-7 . The button's Code Connections tab
You'll see a section labeled CCControl that you'll only see on user-interface nodes,
namely Button, Text Field, and Slider nodes. This is where you can specify a selector, also
known as “the name of a method” for those not afraid to put it in layman's terms. That's
the message being sent (or simply “the method being called”) when the button is pressed.
Enter exitButtonPressed in the Selector text field. As for Target , leave it on Document
root . Be sure to leave the Continuous check box unchecked, or else the method would
run every frame while the user keeps the button tapped or pressed.
What happens now if you publish and run the code, and then press the button? Darn! It's
still showing the original MainScene.
Changing the Launch Scene
To change the scene with which a SpriteBuilder project launches, open the AppDeleg-
ate.m file in Xcode. Locate the startScene method, and modify it so it loads the
GameScene file:
- (CCScene*) startScene
{
return [CCBReader loadAsScene:@"GameScene"];
}
CCBReader is the class bundled with Cocos2d-Swift that is responsible for loading CCB
files.
The CCBReader methods you are likely to use are loadAsScene and load , which
both load the specified CCB file and return a CCScene and CCNode instance, respect-
Search WWH ::




Custom Search