更改CCLabel文件的updateColor()函數(shù)中的頂點(diǎn)顏色即可,代碼如下:
void Label::updateColor()
{
if (_batchNodes.empty())
{
return;
}
Color4B color4( _displayedColor.r, _displayedColor.g, _displayedColor.b, _displayedOpacity );
// special opacity for premultiplied textures
if (_isOpacityModifyRGB)
{
color4.r *= _displayedOpacity/255.0f;
color4.g *= _displayedOpacity/255.0f;
color4.b *= _displayedOpacity/255.0f;
}
Color4B endColor=Color4B::RED;
// special opacity for premultiplied textures
if (_isOpacityModifyRGB)
{
endColor.r *= _displayedOpacity / 255.0f;
endColor.g *= _displayedOpacity / 255.0f;
endColor.b *= _displayedOpacity / 255.0f;
}
cocos2d::TextureAtlas* textureAtlas;
V3F_C4B_T2F_Quad *quads;
for (auto&& batchNode:_batchNodes)
{
textureAtlas = batchNode->getTextureAtlas();
quads = textureAtlas->getQuads();
auto count = textureAtlas->getTotalQuads();
for (int index = 0; index < count; ++index)
{
quads[index].bl.colors = color4;
quads[index].br.colors = color4;
quads[index].tl.colors = endColor;
quads[index].tr.colors = endColor;
textureAtlas->updateQuad(&quads[index], index);
}
}
}
效果圖:
文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-656410.html
?文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-656410.html
到了這里,關(guān)于Cocos2d-x實(shí)現(xiàn)文字顏色漸變的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!