Time for action – creating transitions with a singleton Layer class
We first need to make sure the layer in question can only be instantiated once.
- The
scene
static method inGameLayer
looks like this:Scene* GameLayer::scene(int level, int levelsCompleted) { // 'scene' is an autorelease object auto scene = Scene::create(); // add layer as a child to scene scene->addChild(GameLayer::create(level, levelsCompleted)); return scene; }
This layer receives two parameters when created: the game level it should load and the number of levels completed by the player. We create a new
Scene
object and addGameLayer
as its child. - But take a look at the static
create
method inGameLayer
:GameLayer * GameLayer::create (int level, int levelsCompleted) { if (!_instance) { _instance = new GameLayer(); } else { _instance->clearLayer(); } _instance->setLevelsCompleted(levelsCompleted); _instance->loadLevel(level); _instance-...