更改CCLabel文件的updateColor()函数中的顶点颜色即可,代码如下:
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);
}
}
}
效果图:
文章来源:https://www.toymoban.com/news/detail-656410.html
文章来源地址https://www.toymoban.com/news/detail-656410.html
到了这里,关于Cocos2d-x实现文字颜色渐变的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!