LabelTTFDistanceFieldEffect::LabelTTFDistanceFieldEffect() { auto size = Director::getInstance()->getWinSize(); auto bg = LayerColor::create(Color4B(200,191,231,255)); this->addChild(bg); TTFConfig ttfConfig("fonts/arial.ttf", 80, GlyphCollection::DYNAMIC,nullptr,true); auto label1 = Label::createWithTTF(ttfConfig,"Glow", TextHAlignment::CENTER, size.width); label1->setPosition( Point(size.width/2, size.height*0.65) ); label1->setColor( Color3B::GREEN ); label1->setAnchorPoint(Point::ANCHOR_MIDDLE); label1->setLabelEffect(LabelEffect::GLOW,Color3B::YELLOW); addChild(label1); auto label2 = Label::createWithTTF(ttfConfig,"Outline", TextHAlignment::CENTER, size.width); label2->setPosition( Point(size.width/2, size.height*0.5) ); label2->setColor( Color3B::RED ); label2->setAnchorPoint(Point::ANCHOR_MIDDLE); label2->setLabelEffect(LabelEffect::OUTLINE,Color3B::BLUE); addChild(label2); auto label3 = Label::createWithTTF(ttfConfig,"Shadow", TextHAlignment::CENTER, size.width); label3->setPosition( Point(size.width/2, size.height*0.35f) ); label3->setColor( Color3B::RED ); label3->setAnchorPoint(Point::ANCHOR_MIDDLE); label3->setLabelEffect(LabelEffect::SHADOW,Color3B::BLACK); addChild(label3); }
bool Label::init() { bool ret = true; if(_fontAtlas) { if (_reusedLetter == nullptr) { _reusedLetter = Sprite::createWithTexture(&_fontAtlas->getTexture(0)); _reusedLetter->setOpacityModifyRGB(_isOpacityModifyRGB); _reusedLetter->retain(); _reusedLetter->setAnchorPoint(Point::ANCHOR_TOP_LEFT); } ret = SpriteBatchNode::initWithTexture(&_fontAtlas->getTexture(0), 30); } if (_useDistanceField) setLabelEffect(LabelEffect::NORMAL,Color3B::BLACK); else if(_useA8Shader) setShaderProgram(ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_A8_COLOR)); else setShaderProgram(ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR)); return ret; }