Game Development Reference
In-Depth Information
the numeric sorting problem. You will no longer see numbered files sorted in
this particular order: Level1 - Level10 - Level2 . At the same time,
the string-formatting code Level%i fits all numbers, from one to gazillions.
Having to consider padded zeros makes every format string more complex than
it needs to be.
With the reference to the GameScene instance, you can send it the
loadLevelNamed: method, passing in the generated level string. You should do so be-
fore presenting the scene so that the scene is fully prepared before it is rendered. The
loadLevelNamed: method is the same one you've already used before, except you
haven't been using it from another class. To prevent the compiler from complaining about
a missing selector declaration, you have to open GameScene.h and add the declaration as
shown in Listing 8-13 .
Listing 8-13 . Declaring the loadLevelNamed: selector
#import "CCNode.h"
@interface GameScene : CCNode <CCPhysicsCollisionDelegate,
CCBAnimationManagerDelegate>
-(void) showPopoverNamed:(NSString*)popoverName;
-(void) removePopover;
-(void) loadLevelNamed:(NSString*)levelCCB;
@end
In GameScene.m , you should now remove the line [self loadLevelNamed:nil];
from the didLoadFromCCB method.
Although this will now successfully load the first level, it's a fallacy. After all, the first
level is already referenced by the GameScene.ccb , yet you aren't loading the particular
level passed in to the loadLevelNamed: method. You should change that now by up-
dating the loadLevelNamed: method in GameScene.m . As highlighted by Listing
8-14 , all the new lines are at the top of the method.
Listing 8-14 . The actual level-loading procedure
-(void) loadLevelNamed:(NSString*)levelCCB
{
Search WWH ::




Custom Search