bool SnakeLayer::init() { maximumLength = 100; itemsPicked = 0; score = 0; bonus = 0; direction = Point::ZERO; speed = 180; LayerColor* lc = LayerColor::create(Color4B(0, 0, 0, 210), PX(1.0f), PY(0.8f)); lc->setPosition(CP(0.5f, 0.5f)); lc->setAnchorPoint(Point(0.5f, 0.5f)); lc->ignoreAnchorPointForPosition(false); addChild(lc); bounds = lc->getBoundingBox(); LayerColor* scorebg = LayerColor::create(Color4B::BLACK, PX(1.0f), PY(0.1f)); scorebg->setPosition(Point::ZERO); addChild(scorebg); addChild(lineGroup = Node::create()); addChild(bonusGroup = Node::create()); addChild(itemGroup = Node::create()); LineNode* line = LineNode::create(CP(0.5f, 0.5f), CP(0.5f, 0.5f)); lineGroup->addChild(line); schedule(schedule_selector(SnakeLayer::considerSpawningBonus), 5.0f); scheduleUpdate(); lblScore = Label::createWithTTF(LS("ScoreColon") + " 0", NORMAL_TTF, 42.0f); lblScore->setColor(Color3B::WHITE); lblScore->setPosition(CP(0.5f, 0.05f)); //lblScore->enableGlow(Color4B::BLACK); //lblScore->enableShadow(Color4B::BLACK, Size::ZERO, 4); addChild(lblScore); string instruction = LS("SNAKE_INSTRUCTIONS"); lblInstruction = Label::createWithTTF(instruction, NORMAL_TTF, 48.0f); lblInstruction->setPosition(CP(0.5f, 0.5f)); lblInstruction->setHorizontalAlignment(TextHAlignment::CENTER); lblInstruction->setColor(Color3B::WHITE); lblInstruction->enableGlow(Color4B::RED); lblInstruction->runAction(RepeatForever::create( Sequence::createWithTwoActions(ScaleTo::create(1.0f, 1.1f), ScaleTo::create(1.0f, 1.0f)))); addChild(lblInstruction); instructionVisible = true; return true; }
bool CLoginLayer::init() { CBaseLayer::initWithColor(Color4B(26,11,24, 255)); m_pListener = EventListenerTouchOneByOne::create(); m_pListener->setSwallowTouches(true); m_pListener->onTouchBegan = CC_CALLBACK_2(CLoginLayer::onTouchBegan, this); m_pListener->onTouchMoved = CC_CALLBACK_2(CLoginLayer::onTouchMoved, this); m_pListener->onTouchEnded = CC_CALLBACK_2(CLoginLayer::onTouchEnded, this); _eventDispatcher->addEventListenerWithSceneGraphPriority(m_pListener,this); m_pBig = Sprite::create("login/login_d1.png"); m_pBig->setPosition(m_winSize.width*0.5,m_winSize.height*0.5); addChild(m_pBig); m_pBig2 = Sprite::create("login/login_d2.png"); m_pBig2->setOpacity(0); m_pBig2->setPosition(m_winSize.width*0.5,m_winSize.height*0.5); addChild(m_pBig2); m_pBig3 = Sprite::create("login/login_d3.png"); m_pBig3->setOpacity(0); m_pBig3->setPosition(m_winSize.width*0.5,m_winSize.height*0.5); addChild(m_pBig3); Size tBg = m_pBig->getBoundingBox().size; m_lBeginTime = 0; m_pBig->runAction(Sequence::create(DelayTime::create(2.5),FadeOut::create(0.5),CallFunc::create([=](){ m_iChangeState = 1; }), NULL)); m_pBig2->runAction(Sequence::create(DelayTime::create(3.5),FadeIn::create(1),DelayTime::create(2.5),FadeOut::create(0.5),CallFunc::create([=](){ m_iChangeState = 2; }),NULL)); m_pBig3->runAction(Sequence::create(DelayTime::create(8),FadeIn::create(1),NULL)); //1024X196 LayerColor *pLayer = LayerColor::create(Color4B(0,0,0,255*0.6),m_winSize.width,196); pLayer->setPosition(0,-m_winSize.height*0.025); addChild(pLayer,1); m_strText = "那是一个众神消逝的时代,那是一片危机四伏的大陆。很难想象,如果没有他,相比其他种族而言如此弱小的人类,到底会如何惨淡的结束。是时代造就了英雄,还是英雄造就了时代?\n"; m_sAuthor = "出自《唯一魔导召唤师的一生》 王国卫队长卡尔 著"; Size tbg = pLayer->getBoundingBox().size; m_pTextInfo = Label::createWithTTF(m_strText.substr(0,1),"fonts/cuti.ttf",30,Size(tbg.width*0.9,0)); m_pTextInfo->setAnchorPoint(Vec2(0.5,1)); m_pTextInfo->setColor(Color3B(205,196,161)); m_pTextInfo->setPosition(tbg.width*0.5,tbg.height*0.85); pLayer->addChild(m_pTextInfo); //,Size(tbg.width*0.9,0) m_pTextAuthor = Label::createWithTTF(m_sAuthor,"fonts/cuti.ttf",25); m_pTextAuthor->setColor(Color3B(205,196,161)); m_pTextAuthor->setAnchorPoint(Vec2(0.5,1)); //-tbg.width*0.05 m_pTextAuthor->setPosition(m_winSize.width-m_pTextAuthor->getContentSize().width*0.5-tbg.width*0.05,m_winSize.height*0.05); m_pTextAuthor->setVisible(false); addChild(m_pTextAuthor,10); scheduleUpdate(); return true; }