Game Development Reference
In-Depth Information
[_levelNode removeFromParent];
CCNode* level = [CCBReader load:levelCCB];
[self addChild:level];
_levelNode = level;
_physicsNode = (CCPhysicsNode*)[_levelNode
getChildByName:@"physics"
recursively:NO];
_physicsNode.debugDraw = _drawPhysicsShapes;
_physicsNode.collisionDelegate = self;
_backgroundNode = [_levelNode
getChildByName:@"background" recursively:NO];
_playerNode = [_physicsNode getChildByName:@"player"
recursively:YES];
[self scrollToTarget:_playerNode];
}
The _levelNode is the reference to the Sub File node currently referencing
Level1.ccb . Loading a level should first remove the existing level. Then CCBReader
loads the levelCCB string originally generated by the shouldLoadLevel: method
in MainMenuLevelSelect.m . The level is then added as a child to the GameScene .
Finally, the _levelNode reference is replaced by the new level. Note that because
_levelNode is a __weak reference, you couldn't assign the node returned from
CCBReader load: directly to it. It would likely be set to nil by the Objective-C
runtime because at that point there would be no strong reference to the level node until the
next line, where it is added as a child.
If you run this now, press Play, and then tap the first-level button, you should enter the
GameScene with the first level loaded as before. Or wait. There's no pause button any-
more.
Silly me. I totally forgot one thing. Take a look at Figure 8-8 .
Figure 8-8 . The default node order in GameScene.ccb
Search WWH ::




Custom Search