bool MainLayer::init() { /*-- 设置整体层属性 --*/ this->setTouchMode(kCCTouchesOneByOne); this->setTouchEnabled(true); this->scheduleUpdate(); CCSize s = CCDirector::sharedDirector()->getWinSize(); this->ignoreAnchorPointForPosition(true); setAnchorPoint(ccp(0.5f, 0.5f)); this->setContentSize(s); setPosition(ccp(s.width / 2, s.height / 2)); CCSize vsize = CCDirector::sharedDirector()->getVisibleSize(); float width = vsize.width / 2; float height = vsize.height / 2; Counter *counter = Counter::sharedCounter(); counter->clearScore(); if (counter->isSound() && !SimpleAudioEngine::sharedEngine()->isBackgroundMusicPlaying()) { SimpleAudioEngine::sharedEngine()->playBackgroundMusic("bgm.mp3", true); } /*-- door --*/ CCAnimation *doorAnimation = CCAnimationCache::sharedAnimationCache()->animationByName("door"); //左侧 CCSprite *leftDoor = CCSprite::createWithSpriteFrameName("door_1.png"); leftDoor->setPosition(ccp(-200, -50)); leftDoor->setAnchorPoint(ccp(0.5, 0.5)); this->addChild(leftDoor); leftDoor->runAction( CCRepeatForever::create(CCAnimate::create(doorAnimation))); //右侧 CCSprite *rightDoor = CCSprite::createWithSpriteFrameName("door_1.png"); rightDoor->setPosition(ccp(200, -50)); rightDoor->setAnchorPoint(ccp(0.5, 0.5)); this->addChild(rightDoor); rightDoor->runAction( CCRepeatForever::create(CCAnimate::create(doorAnimation))); /*-- 分数 --*/ CCLabelTTF *titletxt = CCLabelTTF::create(counter->getStringByKey("score"), counter->getStringByKey("font"), 46); titletxt->setColor(ccc3(98, 104, 191)); titletxt->setAnchorPoint(ccp(0.5, 0.5)); titletxt->setPosition(ccp(0, height - 130)); this->addChild(titletxt); CCNode *scoreLabel = counter->create_label(); scoreLabel->setPosition(ccp(0, height - 200)); scoreLabel->setAnchorPoint(ccp(0.5, 1)); this->addChild(scoreLabel, 3, TAG_SCORE); /*-- role --*/ return true; }