Game Development Reference
In-Depth Information
Changing the Scene on Button Tap
Would be even nicer if tapping the button actually did change to the menu scene, don't
you think? Connecting scenes is a task that you have to code, but it's really straightfor-
ward and the same procedure for all scene transitions. See
Listing 2-1
.
Listing 2-1
.
Changing the scene on button press
-(void) exitButtonPressed
{
NSLog(@"Get me outa here!");
CCScene* scene = [CCBReader loadAsScene:@"MainScene"];
CCTransition* transition = [CCTransition
transitionFadeWithDuration:1.5];
[[CCDirector sharedDirector] presentScene:scene
withTransition:transition];
}
Caution
You should not append the .ccb file extension when loading CCBs.
It's a common and understandable mistake, but CCBReader will fail to load
files where you specify the .ccb extension. Published CCB files are converted to
a binary format optimized for fast loading and compact storage. This binary file
format carries the extension .ccbi—that's .ccb with a trailing
i
. The plain text
format .ccb files aren't actually in the bundle. Therefore, it's important to omit
the file extension in calls to
CCBReader
. Or, perhaps to remind you of the dif-
fering extensions, you can also append the .ccbi extension.
First,
CCBReader
is used to load a SpriteBuilder CCB file as the scene with the
loadAsScene:
method. The
loadAsScene
method is a convenience method. It re-
turns a
CCScene
object with your CCB file's root node as the only child. To better un-
derstand this, here's the equivalent code to
loadAsScene
but implemented using the
load:
method:
CCNode* ccbRootNode = [CCBReader load:@"MainScene"];
CCScene* scene = [CCScene node];
[scene addChild:ccbRootNode];
Search WWH ::
Custom Search