void Label::drawTextSprite(Renderer *renderer, uint32_t parentFlags) { if (_fontDefinition._fontFillColor.r != _textColor.r || _fontDefinition._fontFillColor.g != _textColor.g || _fontDefinition._fontFillColor.b != _textColor.b) { updateContent(); } if (_shadowEnabled && _shadowNode == nullptr) { _shadowNode = Sprite::createWithTexture(_textSprite->getTexture()); if (_shadowNode) { if (_blendFuncDirty) { _shadowNode->setBlendFunc(_blendFunc); } //set camera mask using label's mask. Because _shadowNode may be null when setting the label's camera mask _shadowNode->setCameraMask(getCameraMask()); _shadowNode->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT); _shadowNode->setColor(_shadowColor); _shadowNode->setOpacity(_shadowOpacity * _displayedOpacity); _shadowNode->setPosition(_shadowOffset.width, _shadowOffset.height); Node::addChild(_shadowNode,0,Node::INVALID_TAG); } } if (_shadowNode) { _shadowNode->visit(renderer, _modelViewTransform, parentFlags); } _textSprite->visit(renderer, _modelViewTransform, parentFlags); }
void Label::createShadowSpriteForSystemFont(const FontDefinition& fontDef) { if (!fontDef._stroke._strokeEnabled && fontDef._fontFillColor == _shadowColor3B && (fontDef._fontAlpha == _shadowOpacity)) { _shadowNode = Sprite::createWithTexture(_textSprite->getTexture()); } else { FontDefinition shadowFontDefinition = fontDef; shadowFontDefinition._fontFillColor.r = _shadowColor3B.r; shadowFontDefinition._fontFillColor.g = _shadowColor3B.g; shadowFontDefinition._fontFillColor.b = _shadowColor3B.b; shadowFontDefinition._fontAlpha = _shadowOpacity; shadowFontDefinition._stroke._strokeColor = shadowFontDefinition._fontFillColor; shadowFontDefinition._stroke._strokeAlpha = shadowFontDefinition._fontAlpha; auto texture = new (std::nothrow) Texture2D; texture->initWithString(_utf8Text.c_str(), shadowFontDefinition); _shadowNode = Sprite::createWithTexture(texture); texture->release(); } if (_shadowNode) { if (_blendFuncDirty) { _shadowNode->setBlendFunc(_blendFunc); } _shadowNode->setCameraMask(getCameraMask()); _shadowNode->setGlobalZOrder(getGlobalZOrder()); _shadowNode->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT); _shadowNode->setPosition(_shadowOffset.width, _shadowOffset.height); _shadowNode->retain(); _shadowNode->updateDisplayedColor(_displayedColor); _shadowNode->updateDisplayedOpacity(_displayedOpacity); } }
void Label::createShadowSpriteForSystemFont() { if (!_fontDefinition._stroke._strokeEnabled && _fontDefinition._fontFillColor == _shadowColor3B && (_fontDefinition._fontAlpha == _shadowOpacity)) { _shadowNode = Sprite::createWithTexture(_textSprite->getTexture()); } else { auto shadowFontDefinition = _fontDefinition; shadowFontDefinition._fontFillColor.r = _shadowColor3B.r; shadowFontDefinition._fontFillColor.g = _shadowColor3B.g; shadowFontDefinition._fontFillColor.b = _shadowColor3B.b; shadowFontDefinition._fontAlpha = _shadowOpacity; shadowFontDefinition._stroke._strokeColor = shadowFontDefinition._fontFillColor; shadowFontDefinition._stroke._strokeAlpha = shadowFontDefinition._fontAlpha; auto texture = new (std::nothrow) Texture2D; texture->initWithString(_originalUTF8String.c_str(), shadowFontDefinition); _shadowNode = Sprite::createWithTexture(texture); texture->release(); } if (_shadowNode) { if (_blendFuncDirty) { _shadowNode->setBlendFunc(_blendFunc); } _shadowNode->setCameraMask(getCameraMask()); _shadowNode->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT); _shadowNode->setPosition(_shadowOffset.width, _shadowOffset.height); Node::addChild(_shadowNode, 0, Node::INVALID_TAG); _shadowNode->updateDisplayedColor(_displayedColor); _shadowNode->updateDisplayedOpacity(_displayedOpacity); } }
void Label::createSpriteForSystemFont(const FontDefinition& fontDef) { _currentLabelType = LabelType::STRING_TEXTURE; auto texture = new (std::nothrow) Texture2D; texture->initWithString(_utf8Text.c_str(), fontDef); _textSprite = Sprite::createWithTexture(texture); //set camera mask using label's camera mask, because _textSprite may be null when setting camera mask to label _textSprite->setCameraMask(getCameraMask()); _textSprite->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT); this->setContentSize(_textSprite->getContentSize()); texture->release(); if (_blendFuncDirty) { _textSprite->setBlendFunc(_blendFunc); } _textSprite->retain(); _textSprite->updateDisplayedColor(_displayedColor); _textSprite->updateDisplayedOpacity(_displayedOpacity); }
void Label::createSpriteWithFontDefinition() { _currentLabelType = LabelType::STRING_TEXTURE; auto texture = new (std::nothrow) Texture2D; texture->initWithString(_originalUTF8String.c_str(),_fontDefinition); _textSprite = Sprite::createWithTexture(texture); //set camera mask using label's camera mask, because _textSprite may be null when setting camera mask to label _textSprite->setCameraMask(getCameraMask()); _textSprite->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT); this->setContentSize(_textSprite->getContentSize()); texture->release(); if (_blendFuncDirty) { _textSprite->setBlendFunc(_blendFunc); } Node::addChild(_textSprite,0,Node::INVALID_TAG); _textSprite->updateDisplayedColor(_displayedColor); _textSprite->updateDisplayedOpacity(_displayedOpacity); }
void Label::createSpriteForSystemFont() { _currentLabelType = LabelType::STRING_TEXTURE; if (!_compatibleMode) { _fontDefinition._fontName = _systemFont; _fontDefinition._fontSize = _systemFontSize; _fontDefinition._alignment = _hAlignment; _fontDefinition._vertAlignment = _vAlignment; _fontDefinition._dimensions.width = _labelWidth; _fontDefinition._dimensions.height = _labelHeight; _fontDefinition._fontFillColor.r = _textColor.r; _fontDefinition._fontFillColor.g = _textColor.g; _fontDefinition._fontFillColor.b = _textColor.b; _fontDefinition._fontAlpha = _textColor.a; _fontDefinition._shadow._shadowEnabled = false; if (_currLabelEffect == LabelEffect::OUTLINE && _outlineSize > 0) { _fontDefinition._stroke._strokeEnabled = true; _fontDefinition._stroke._strokeSize = _outlineSize; _fontDefinition._stroke._strokeColor.r = _effectColor.r; _fontDefinition._stroke._strokeColor.g = _effectColor.g; _fontDefinition._stroke._strokeColor.b = _effectColor.b; _fontDefinition._stroke._strokeAlpha = _effectColor.a; } else { _fontDefinition._stroke._strokeEnabled = false; } #if (CC_TARGET_PLATFORM != CC_PLATFORM_ANDROID) && (CC_TARGET_PLATFORM != CC_PLATFORM_IOS) if (_fontDefinition._stroke._strokeEnabled) { CCLOGERROR("Currently only supported on iOS and Android!"); } _fontDefinition._stroke._strokeEnabled = false; #endif } auto texture = new (std::nothrow) Texture2D; texture->initWithString(_originalUTF8String.c_str(), _fontDefinition); _textSprite = Sprite::createWithTexture(texture); //set camera mask using label's camera mask, because _textSprite may be null when setting camera mask to label _textSprite->setCameraMask(getCameraMask()); _textSprite->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT); this->setContentSize(_textSprite->getContentSize()); texture->release(); if (_blendFuncDirty) { _textSprite->setBlendFunc(_blendFunc); } Node::addChild(_textSprite, 0, Node::INVALID_TAG); _textSprite->updateDisplayedColor(_displayedColor); _textSprite->updateDisplayedOpacity(_displayedOpacity); }