Game Development Reference
In-Depth Information
You then just need to add the selector shown in
Listing 8-19
. Add it just above the
@end
line.
Listing 8-19
.
Loading the next level
-(void) shouldLoadNextLevel
{
[GameState sharedGameState].currentLevel += 1;
[SceneManager presentGameScene];
}
This should be pretty straightforward. The current level is increased by one because the
player is going to the next level. The
presentGameScene
method then presents a new
GameScene
instance and instructs the instance to load the current level.
This is pretty much it. However, you don't have any additional levels yet. But you can still
try one thing: play the first level and reach the exit. Confirm that the Level Complete pop-
over is shown, and then tap the
Next Level
button. Doing this will most certainly cause a
crash because there's simply no
Level2.ccb
in your project yet. But if you relaunch the app
and tap the play button you should notice that the Level 2 button is no longer grayed out.
So, in principle, the unlocking part works.
Tip
If you ever need to reset the highest unlocked level, just delete the app
from the device and simulator. This will also delete all items stored by the app,
including its User Defaults dictionary.
Adding More Levels
There's a shortcut to adding more levels. Open Finder, and locate the
LearnSpriteBuild-
er.spritebuilder
project folder. Inside that folder, you'll find the
Packages/SpriteBuilder
Resources.sbpack
folder, which contains all the files SpriteBuilder shows in its
File View
.
Therefore, if you move into the
Levels
folder, you'll find your
Level1.ccb
and
DummyLevel.ccb
files, among others.
Search WWH ::
Custom Search