void Text::copySpecialProperties(Widget *widget) { Text* label = dynamic_cast<Text*>(widget); if (label) { setFontName(label->_fontName); setFontSize(label->getFontSize()); setTextColor(label->getTextColor()); setString(label->getString()); setTouchScaleChangeEnabled(label->_touchScaleChangeEnabled); setTextHorizontalAlignment(label->_labelRenderer->getHorizontalAlignment()); setTextVerticalAlignment(label->_labelRenderer->getVerticalAlignment()); setTextAreaSize(label->_labelRenderer->getDimensions()); setContentSize(label->getContentSize()); LabelEffect effectType = label->getLabelEffectType(); if (effectType == LabelEffect::GLOW) { enableGlow(label->getEffectColor()); } else if (effectType == LabelEffect::OUTLINE) { enableOutline(label->getEffectColor(),label->getOutlineSize()); } if (label->isShadowEnabled()) { enableShadow(label->getShadowColor(),label->getShadowOffset(),label->getShadowBlurRadius()); } } }
void Label::setLabelEffect(LabelEffect effect,const Color3B& effectColor) { switch (effect) { case cocos2d::LabelEffect::NORMAL: disableEffect(); break; case cocos2d::LabelEffect::OUTLINE: enableOutline(Color4B(effectColor)); break; case cocos2d::LabelEffect::SHADOW: enableShadow(Color4B(effectColor)); break; case cocos2d::LabelEffect::GLOW: enableGlow(Color4B(effectColor)); break; default: break; } }
bool GameOver::init() { if ( !Layer::init() ) { return false; } director = Director::getInstance(); visibleSize = director->getVisibleSize(); Vec2 origin = director->getVisibleOrigin(); auto pauseItem = MenuItemImage::create( "play.png", "play_pressed.png", CC_CALLBACK_1(GameOver::exitPause, this)); pauseItem->setPosition(Vec2(origin.x + visibleSize.width - pauseItem->getContentSize().width / 2, origin.y + pauseItem->getContentSize().height / 2)); auto menu = Menu::create(pauseItem, NULL); menu->setPosition(Vec2::ZERO); this->addChild(menu, 1); auto bg = Sprite::create("background.png"); bg->setAnchorPoint(Vec2()); bg->setPosition(0,0); this->addChild(bg, -1); auto label = Label::createWithTTF("Game Over", "fonts/Marker Felt.ttf", 96); label->enableOutline(Color4B(255, 0, 0, 100),6); label->enableGlow(Color4B(255, 0, 0, 255)); label->enableShadow(); label->setPosition(origin.x + visibleSize.width/2, origin.y + visibleSize.height /2); this->addChild(label, 1); auto label2 = Label::createWithSystemFont("Your score is", "Arial", 48); label2->setPosition(origin.x + visibleSize.width/2,origin.y + visibleSize.height /2.5); this->addChild(label2, 1); char scoreText[32]; int score = UserDefault::getInstance()->getIntegerForKey("score",0); sprintf(scoreText, "%d", score); auto label3 = Label::createWithBMFont("font.fnt", scoreText); label3->setPosition(origin.x + visibleSize.width/2,origin.y + visibleSize.height /3.5); this->addChild(label3, 1); return true; }
Scene* Chapter6_1::createScene() { cocos2d::Rect visibleRect = Director::getInstance()->getOpenGLView()->getVisibleRect(); Size visibleSize = Director::getInstance()->getVisibleSize(); Vec2 origin = Director::getInstance()->getVisibleOrigin(); int index=2; // create a scene auto scene = Scene::create(); auto layer = LayerColor::create(Color4B::GRAY); scene->addChild(layer); // add title auto label = LabelTTF::create("Label", "Marker Felt.ttf", 32); label->setPosition(Vec2(visibleRect.origin.x+visibleRect.size.width/2, visibleRect.origin.y+visibleRect.size.height/2).x, Vec2(visibleRect.origin.x+visibleRect.size.width/2, visibleRect.origin.y+visibleRect.size.height).y - 30); scene->addChild(label, -1); //add the menu item for back to main menu label = LabelTTF::create("MainMenu", "Marker Felt.ttf", 32); auto menuItem = MenuItemLabel::create(label); menuItem->setCallback([&](cocos2d::Ref *sender) { Director::getInstance()->replaceScene(Chapter6::createScene()); }); auto menu = Menu::create(menuItem, nullptr); menu->setPosition(Vec2::ZERO); menuItem->setPosition(Vec2(visibleRect.origin.x+visibleRect.size.width - 80, visibleRect.origin.y + 25)); scene->addChild(menu, 1); // this is for Labels section of the Programmers Guide // 1. BMFont auto myLabel = Label::createWithBMFont("bitmapRed.fnt", "LabelBMFont"); myLabel->setPosition(Vec2(origin.x+visibleSize.width/2, origin.y+visibleSize.height/2).x, (Vec2(origin.x+visibleSize.width/2, origin.y+visibleSize.height).y - (++index) * 40)); scene->addChild(myLabel, 1); // 2. LabelTTF auto myLabel2 = Label::createWithTTF("LabelTTF", "Marker Felt.ttf", 32); myLabel2->setColor(Color3B::RED); myLabel2->setPosition(Vec2(origin.x+visibleSize.width/2, origin.y+visibleSize.height/2).x, (Vec2(origin.x+visibleSize.width/2, origin.y+visibleSize.height).y - (++index) * 40)); scene->addChild(myLabel2, 1); // 3. LabelTTF with TTFConfig // create a TTFConfig files for labels to share TTFConfig labelConfig; labelConfig.fontFilePath = "Marker Felt.ttf"; labelConfig.fontSize = 32; auto myLabel3 = Label::createWithTTF(labelConfig, "LabelTTF from TTFConfig"); myLabel3->setColor(Color3B::RED); myLabel3->setPosition(Vec2(origin.x+visibleSize.width/2, origin.y+visibleSize.height/2).x, (Vec2(origin.x+visibleSize.width/2, origin.y+visibleSize.height).y - (++index) * 40)); scene->addChild(myLabel3, 1); // 4. Label using SystemFont auto myLabel4 = Label::createWithSystemFont("Label using SystemFont", "Arial", 32); myLabel4->setColor(Color3B::RED); myLabel4->setPosition(Vec2(origin.x+visibleSize.width/2, origin.y+visibleSize.height/2).x, (Vec2(origin.x+visibleSize.width/2, origin.y+visibleSize.height).y - (++index) * 40)); scene->addChild(myLabel4, 1); // 5. LabelTTF with shadow, outline and glow auto myLabel5 = Label::createWithTTF("LabelTTF with Shadow", "Marker Felt.ttf", 32); myLabel5->enableShadow(); myLabel5->setColor(Color3B::RED); myLabel5->setPosition(Vec2(origin.x+visibleSize.width/2, origin.y+visibleSize.height/2).x, (Vec2(origin.x+visibleSize.width/2, origin.y+visibleSize.height).y - (++index) * 40)); scene->addChild(myLabel5, 1); auto myLabel6 = Label::createWithTTF("LabelTTF with Outline", "Marker Felt.ttf", 32); myLabel6->setTextColor(Color4B::RED); //setColor will change the color of the whole label with effects as if 3.4 // myLabel6->setColor(Color3B::RED); myLabel6->enableOutline(Color4B::WHITE, 1); myLabel6->setPosition(Vec2(origin.x+visibleSize.width/2, origin.y+visibleSize.height/2).x, (Vec2(origin.x+visibleSize.width/2, origin.y+visibleSize.height).y - (++index) * 40)); scene->addChild(myLabel6, 1); auto myLabel7 = Label::createWithTTF("LabelTTF with Glow", "Marker Felt.ttf", 32); myLabel7->enableGlow(Color4B::YELLOW); myLabel7->setTextColor(Color4B::RED); myLabel7->setPosition(Vec2(origin.x+visibleSize.width/2, origin.y+visibleSize.height/2).x, (Vec2(origin.x+visibleSize.width/2, origin.y+visibleSize.height).y - (++index) * 40)); scene->addChild(myLabel7, 1); // return the scene return scene; }
void BackGroundLayer::LoadNode() { topBG = Sprite::create("toppic.png"); topBG->setPosition(Vec2(0, 640)); topBG->setAnchorPoint(Vec2(0, 1)); topBG->setScaleX(1.8750f); topBG->setScaleY(1.3370f); topBG->runAction(RepeatForever::create(Sequence::create(MoveBy::create(15, Vec2(960.0f, 0)), CallFunc::create([&](){ topBG->setPosition(Vec2(0, 640)); }), NULL))); this->addChild(topBG); topBGclone = Sprite::create("toppic.png"); topBGclone->setPosition(Vec2(0, 640)); topBGclone->setAnchorPoint(Vec2(1, 1)); topBGclone->setScaleX(1.8750f); topBGclone->setScaleY(1.3370f); topBGclone->runAction(RepeatForever::create(Sequence::create(MoveBy::create(15, Vec2(960, 0)), CallFunc::create([&](){ topBGclone->setPosition(Vec2(0, 640)); }), NULL))); this->addChild(topBGclone); buttomBG = PVEffectSprite::create("miku.jpg"); buttomBG->setPosition(Vec2(0, 0)); buttomBG->setAnchorPoint(Vec2(0, 0)); buttomBG->setScaleY(0.738f); buttomBG->setName("buttomBG"); buttomBG->retain(); this->addChild(buttomBG); //歌词结点 auto lyrcisNode = Node::create(); lyrcisNode->setPosition(Vec2(300.0f, 470.0f)); lyrcisNode->setName("lyrcisNode"); buttomBG->addChild(lyrcisNode); //歌词特效结点 auto lyrcisParticleNode = Node::create(); lyrcisParticleNode->setPosition(Vec2(300.0f, 470.0f)); lyrcisParticleNode->setName("lyrcisParticleNode"); buttomBG->addChild(lyrcisParticleNode); //初始化歌词Node,歌词Node包含5个歌词子结点 for (int i = 0; i < 5; ++i) { auto lyrcis = Label::create(); lyrcis->setAlignment(TextHAlignment::LEFT); lyrcis->setOpacity(0);//便于开始的FadeIn动作 lyrcis->setSystemFontSize(30); lyrcis->setPositionY(-i * 40); lyrcis->setColor(Color3B{ 241, 125, 170 }); #if (CC_TARGET_PLATFORM != CC_PLATFORM_ANDROID) lyrcis->enableOutline(Color4B(255, 192, 203, 255), 1); lyrcis->enableGlow(Color4B(255, 255, 255, 255)); #endif lyrcisNode->addChild(lyrcis); } auto lyrcisParticl = ParticleSystemQuad::create("particle/star.plist"); //歌词特效粒子 lyrcisParticl->setPositionY(40); lyrcisParticl->setTotalParticles(20); lyrcisParticl->setVisible(false); lyrcisParticl->setName("lyrcisParticle"); lyrcisParticleNode->addChild(lyrcisParticl); //触摸粒子 touchparticle = ParticleSystemQuad::create("particle/touch.plist"); touchparticle->setLocalZOrder(2); touchparticle->ignoreAnchorPointForPosition(true); touchparticle->setVisible(true); this->addChild(touchparticle); //初始化魂进度条 soulProgBar = ProgressTimer::create(Sprite::create("progressUp.png")); soulProgBar->setType(ProgressTimer::Type::BAR); soulProgBar->setPosition(Vec2(250, 550)); soulProgBar->ignoreAnchorPointForPosition(true); soulProgBar->setMidpoint(Point(0, 1)); soulProgBar->setBarChangeRate(Point(1, 0)); soulProgBar->setPercentage(0); this->addChild(soulProgBar); //添加进度条背景 auto soulProgBarBG = Sprite::create(); soulProgBarBG->setSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("progressDown.png")); soulProgBarBG->setPosition(Vec2(-5, -25)); soulProgBarBG->setAnchorPoint(Vec2(0, 0)); soulProgBarBG->setName("soul_progBarBG"); soulProgBarBG->setLocalZOrder(-1); soulProgBar->addChild(soulProgBarBG); scrollBar_Background = UVEffectSprite::create(); //初始化鼓面背景层 scrollBar_Background->setSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("sfieldbg.png")); scrollBar_Background->setPosition(Vec2(92.65f, 410.83f)); //设置绝对坐标 scrollBar_Background->setAnchorPoint(Vec2(0, 0));//设置坐标 scrollBar_Background->setScaleX(1.6885f); scrollBar_Background->setScaleY(1.5645f); scrollBar_Background->retain(); this->addChild(scrollBar_Background); scrollBar = Node::create(); //初始化鼓面 scrollBar->setPosition(Vec2(92.65f, 410.83f));//设置绝对坐标 scrollBar->setAnchorPoint(Vec2(0, 0));//设置坐标 scrollBar->setScaleX(1.6885f); scrollBar->setScaleY(1.5645f); scrollBar->setContentSize(scrollBar_Background->getContentSize());//复制上一层的长度 this->addChild(scrollBar); auto scrollBarGu = Node::create(); //滚动条鼓面结点 scrollBarGu->setPosition(Vec2(0, 0)); scrollBarGu->setLocalZOrder(2); scrollBar->addChild(scrollBarGu); scrollBarClone = Node::create(); scrollBarClone->setName("scrollBarClone"); scrollBarClone->setAnchorPoint(Vec2(0, 0)); scrollBarClone->setPosition(Vec2(512, 0)); auto scrollBarCloneGu = Node::create();//滚动副条鼓面结点 scrollBarCloneGu->setPosition(Vec2(0, 0)); scrollBarClone->addChild(scrollBarCloneGu); scrollBar->addChild(scrollBarClone); GUcharMap = Label::createWithCharMap("combonumber_balloon.png", 20, 24, '0'); //测试计数 GUcharMap->setAnchorPoint(Vec2(0, 0)); GUcharMap->setPosition(Vec2(0, -30)); GUcharMap->setString("0");// 初始化为0分 GUcharMap->setGlobalZOrder(4); scrollBar->addChild(GUcharMap); GUcharMapClone = Label::createWithCharMap("combonumber_balloon.png", 20, 24, '0'); //测试计数 GUcharMapClone->setAnchorPoint(Vec2(0, 0)); GUcharMapClone->setString("0");// 初始化为0分 GUcharMapClone->setGlobalZOrder(4); GUcharMapClone->setPosition(Vec2(0, -30)); scrollBarClone->addChild(GUcharMapClone); #pragma region 初始游戏谱面 for (int i = 0; i < DrumSurfaceLoader::PerDrumCount; ++i) //初始化 scrollBarGu与 scrollBarCloneGu的结点 { auto tempSprite = Sprite::create(); tempSprite->setVisible(false); tempSprite->setPosition(Vec2((i % DrumSurfaceLoader::PerDrumCount) * scrollBar->getContentSize().width / DrumSurfaceLoader::PerDrumCount, 30)); scrollBarGu->addChild(tempSprite); auto tempSprite2 = Sprite::create(); tempSprite2->setVisible(false); tempSprite2->setPosition(Vec2((i % DrumSurfaceLoader::PerDrumCount) * scrollBar->getContentSize().width / DrumSurfaceLoader::PerDrumCount, 30)); scrollBarCloneGu->addChild(tempSprite2); } scrollBarSpriteVector = scrollBarGu->getChildren(); for (const auto &node : scrollBarCloneGu->getChildren()) { scrollBarSpriteVector.pushBack(node); } #pragma endregion }