by Renan » Fri Aug 13, 2010 10:50 pm
Mike,
I have been working with multiple scenes as i mentioned in the TileMap section and something that is really bugging me is being able to use the same player instance in every scene. The player itself is allocated in the GameScene method initNewGameState, but when you use more than one scene accessing that instance player made me put some weird code together in order to work:
// Instance of a scene.
GameScene *oldScene;
// The scene i just came from.
oldScene = [sharedGameController.gameScenes objectForKey:@"game"];
// This player is declared in the .h of the scene i am going to as Player *player but is not allocated again. The new player gets the "old" player and can manipulate the original afterwards.
player = oldScene.player;
This was the way i found to pass the player from one scene to another. It worked so far never had any bug going in and out of the scenes but feels like i am cheating the code or something. Is this the right way to do this? Should i invoke the singleton in any way?
Renan.