cocos2d: maintain state through levels

Quick hack if you don’t want to bother to add a singleton to your project and want to reload or swap a level while maintaining some data.

-(void) nextLevel {
	CCScene *scene = [[game_ class] scene];

	for (CCNode *node in scene.children) {
		if ([node isKindOfClass:[game_ class]]) {
			GameNode *gn = (GameNode*)node;
			gn.level = game_.level;
			gn.totalScore = game_.totalScore;

	[[CCDirector sharedDirector] replaceScene: [CCTransitionMoveInT transitionWithDuration:1.0f scene:scene]];