Game Development Reference
In-Depth Information
compatible for those levels where you haven't replaced the player with the new soft-body
player. Add the line highlighted in Listing 10-4 .
Listing 10-4 . An ivar that is set when the player node is the soft-body version
@implementation GameScene
{
__weak CCNode* _levelNode;
__weak CCPhysicsNode* _physicsNode;
__weak CCNode* _playerNode;
__weak CCNode* _backgroundNode;
__weak GameMenuLayer* _gameMenuLayer;
__weak GameMenuLayer* _popoverMenuLayer;
CGFloat _playerNudgeRightVelocity;
CGFloat _playerNudgeUpVelocity;
CGFloat _playerMaxVelocity;
BOOL _acceleratePlayer;
BOOL _drawPhysicsShapes;
BOOL _softBodyPlayer;
}
Then locate the loadLevelNamed: method. Replace the code at the end of
loadLevelNamed: so that the end of the method looks like Listing 10-5 . To be pre-
cise, the if condition needs to be added while the scrollToTarget: method is re-
placed by the one in Listing 10-5 .
Listing 10-5 . Determining the soft-body player and updating _playerNode accordingly
-(void) loadLevelNamed:(NSString*)levelCCB
{
// ... previous code omitted
_playerNode = [_physicsNode getChildByName:@"player"
recursively:YES];
// Soft-body player's first child node is the actual
player sprite
if (_playerNode.children.count > 0)
{
CCNode* center = _playerNode.children.firstObject;
Search WWH ::




Custom Search