bool GameOverScene::init() { if(!Layer::init()) { return false; } auto visibleSize = Director::getInstance()->getVisibleSize(); auto origin = Director::getInstance()->getVisibleOrigin(); UserDefault* userScore = UserDefault::getInstance(); if(score >= userScore->getIntegerForKey( "highscore" )) { userScore->setIntegerForKey( "highscore", score ); } userScore->flush(); //create background for game over scene auto background = Sprite::create("FlappyResources/Background.png"); background->setPosition(origin.x + visibleSize.width / 2, origin.y + visibleSize.height / 2); this->addChild(background); //create retry item auto retry = MenuItemImage::create( "FlappyResources/Retry_Button.png", "FlappyResources/Retry_Button_Clicked.png", CC_CALLBACK_1(GameOverScene::goToGameScene, this) ); retry->setPosition( origin.x + visibleSize.width / 2, origin.y + visibleSize.height / 2 ); //create quit item auto quit = MenuItemImage::create( "FlappyResources/Menu_Button.png", "FlappyResources/Menu_Button_Clicked.png", CC_CALLBACK_1(GameOverScene::goToMainMenuScene, this) ); quit->setPosition( origin.x + visibleSize.width / 2, origin.y + visibleSize.height / 2 - quit->getContentSize().height * 2); //create menu auto menu = Menu::create( retry, quit, NULL ); menu->setPosition( Vec2(0, 0) ); //create label score auto stringScore = __String::createWithFormat( "Your score: %d", score ); auto labelScore = LabelTTF::create( stringScore->getCString(), "fonts/Marker Belt.ttf", 50 ); labelScore->setPosition( origin.x + labelScore->getContentSize().width, origin.y + visibleSize.height / 2 + labelScore->getContentSize().height * 4 ); labelScore->setFontFillColor( Color3B::YELLOW ); //create label display best score auto stringBestScore = __String::createWithFormat( "High score: %d", userScore->getIntegerForKey( "highscore" ) ); auto labelHighScore = LabelTTF::create( stringBestScore->getCString(), "fonts/Marker Belt.ttf", 50 ); labelHighScore->setPosition( origin.x + labelScore->getContentSize().width + visibleSize.width / 2, origin.y + visibleSize.height / 2 + labelHighScore->getContentSize().height * 4); labelHighScore->setFontFillColor( Color3B::RED ); this->addChild( menu ); this->addChild( labelScore ); this->addChild( labelHighScore ); return true; }
void CCRichLabelTTF::_updateWithTextDefinition(ccFontDefinition & textDefinition, bool mustUpdateTexture) { m_tDimensions = CCSizeMake(textDefinition.m_dimensions.width, textDefinition.m_dimensions.height); m_hAlignment = textDefinition.m_alignment; m_vAlignment = textDefinition.m_vertAlignment; m_pFontName = new std::string(textDefinition.m_fontName); m_fFontSize = textDefinition.m_fontSize; // shadow if ( textDefinition.m_shadow.m_shadowEnabled ) { enableShadow(textDefinition.m_shadow.m_shadowOffset, textDefinition.m_shadow.m_shadowOpacity, textDefinition.m_shadow.m_shadowBlur, false); } // stroke if ( textDefinition.m_stroke.m_strokeEnabled ) { enableStroke(textDefinition.m_stroke.m_strokeColor, textDefinition.m_stroke.m_strokeSize, false); } // fill color setFontFillColor(textDefinition.m_fontFillColor, false); if (mustUpdateTexture) updateTexture(); }
/// LabelTTFOpacityTest LabelTTFOpacityTest::LabelTTFOpacityTest() { auto s = Director::getInstance()->getWinSize(); auto layer = LayerColor::create(Color4B(128, 128, 128, 255)); addChild(layer, -10); auto label1 = LabelTTF::create("Testing opacity", "Marker Felt", 48); addChild(label1); label1->setFontFillColor(Color3B::RED); label1->setPosition(Vec2(s.width/2, s.height/2)); auto fadeOut = FadeOut::create(2); auto fadeIn = FadeIn::create(2); auto seq = Sequence::create(fadeOut, fadeIn, nullptr); auto forever = RepeatForever::create(seq); label1->runAction(forever); }