// on "init" you need to initialize your instance bool GameLayer::init() { ////////////////////////////// // 1. super init first if ( !CCLayer::init() ) { return false; } //get screen size _screenSize = CCDirector::sharedDirector()->getWinSize(); _running = false; //create game screen elements createGameScreen(); //create object pools createPools(); //create CCActions createActions(); //create array to store all falling objects (will use it in collision check) _fallingObjects = CCArray::createWithCapacity(40); _fallingObjects->retain(); //listen for touches this->setTouchEnabled(true); //create main loop this->schedule(schedule_selector(GameLayer::update)); SimpleAudioEngine::sharedEngine()->playBackgroundMusic("background.mp3", true); return true; }
GameLayer::GameLayer() { _screenSize = CCDirector::sharedDirector()->getWinSize(); _running = false; createScreen(); std::string levelsFile = CCFileUtils::sharedFileUtils()->fullPathForFilename("levels.plist"); _levels = CCArray::createWithContentsOfFileThreadSafe(levelsFile.c_str()); _levels->retain(); initPhysics(); createPools(); setTouchEnabled( true ); setAccelerometerEnabled( true ); }