bool HelpLayer::init() { bool bRet = false; do { CC_BREAK_IF(!CCLayer::init()); CCSize size = CCDirector::sharedDirector()->getWinSize(); // 1.黑色半透明背景 ccColor4B color = ccc4(0, 0, 0, 190); setColorLayer(CCLayerColor::create(color)); m_pColorLayer->setPosition(0, 0); m_pColorLayer->setContentSize(size); this->addChild(m_pColorLayer, 1); // 2.主框架 setFrame(CCSprite::create()); m_pFrame->initWithFile(I18N_FILE("StageBase_help_frame.png")); m_pFrame->setPosition(ccp(size.width / 2, m_pFrame->boundingBox().size.height / 2 + size.height)); this->addChild(m_pFrame, 2); // 3.退出键 setMenu(MyMenu::create()); m_pMenu->setPosition(CCPointZero); m_pFrame->addChild(m_pMenu, 1); CCMenuItemImage *pBack = new CCMenuItemImage(); pBack->initWithNormalImage( I18N_FILE("StageBase_help_back_normal.png"), I18N_FILE("StageBase_help_back_pressed.png"), I18N_FILE("StageBase_help_back_normal.png"), this, menu_selector(HelpLayer::backCallback)); pBack->setPosition(ccp(385, 58)); m_pMenu->addChild(pBack); // 禁止后层的按键,不写的话得手动remove from dispatcher,否则本类不会被析构 this->setTouchEnabled(true); bRet = true; }while(0); return bRet; }
void Stage1_6Layer::initHelloBlock() { GameObject* pBlock = GameObject::create(); pBlock->initWithFile(I18N_FILE("Stage1_6_hello.png")); pBlock->setLeftBottomPostion(tccp(-5,4)); this->addChild(pBlock); float textSize = 30; CCString* str = CCString::createWithFormat("%d",TOTAL_COUNT); setCountLabel(CCLabelTTF::create(str->getCString(), "Arial", textSize)); m_pCountLabel->setColor(ccBLACK); m_pCountLabel->setPosition(ccp(250, 288)); this->addChild(m_pCountLabel, 10); }