Cocos2d-x实现文字颜色渐变

这篇具有很好参考价值的文章主要介绍了Cocos2d-x实现文字颜色渐变。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

更改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);
        }
    }
}

效果图:

cocos2dx 文字渐变,Cocos2dx,cocos2d,游戏引擎

 文章来源地址https://www.toymoban.com/news/detail-656410.html

到了这里,关于Cocos2d-x实现文字颜色渐变的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • win10 vs2022 搭建 cocos2d-x 3.17 开发环境

    https://cocos2d-x.org/download/ 也可以在 github 下载 https://github.com/cocos2d/cocos2d-x/tags https://docs.cocos2d-x.org/cocos2d-x/v3/zh/ https://docs.cocos2d-x.org/api-ref/cplusplus/v3x/index.html 需要 python2 , 安装后可以用 python2 的绝对路径运行 cocos 的 setup.py 如何没有把 python2 加入到环境变量, 可以修改引擎路径下

    2024年02月08日
    浏览(31)
  • 如何将cocos2d-x js打包部署到ios上 Mac M1系统

    项目环境 cocos2d-x 3.13 xcode 12 mac m1 big sur 先找到你的项目 使用xcode软件打开上面这个文件 打开后应该是这个样子 执行编译运行就好了 可能会碰到的错误 在xcode11版本以上都会有这个错误,这是因为iOS11+废弃了system。 将上面代码修改为 解决方案地址 remove \\\"system\\\" usage by minggo ·

    2024年02月22日
    浏览(34)
  • cocos2dx学习之UIListView.cpp

    /**************************************************************************** Copyright (c) 2013-2017 Chukong Technologies Inc. http://www.cocos2d-x.org Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \\\"Software\\\"), to deal in the Software without restriction, including witho

    2024年02月11日
    浏览(30)
  • cocos2dx学习之UIListView.h

    /**************************************************************************** Copyright (c) 2013-2017 Chukong Technologies Inc. http://www.cocos2d-x.org Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \\\"Software\\\"), to deal in the Software without restriction, including witho

    2024年02月11日
    浏览(27)
  • cocos2dx上做边下边玩小包热更

    因为公司业务需求需要做边下边玩的小包下载,在这里记录一下思路 下载库我使用的是cocos2dx 4.x的CCDownloader来下载文件 大体思路就是hook住fileutils中的getFileData函数和isFileExist函数。 isFileExist:无论初始包里文件是否存在,只要文件是游戏的资源文件这里都要返回“文件存在”

    2024年02月03日
    浏览(28)
  • cocos2dx ​​Animate3D(二)

    扭曲旋转特效 源码 示例 瓷砖晃动特效 源码 示例 破碎的3D瓷砖特效 源码 示例 瓷砖洗牌特效 源码 示例 FadeOutTRTiles :淡出效果,从左下角到右上角 FadeOutBLTiles :淡出效果,从右上角到左下角 FadeOutUpTiles :折叠效果,从下到上 FadeOutDownTiles :折叠效果,从上到下 示例 方块消

    2024年02月05日
    浏览(27)
  • cocos2dx游戏项目,集成到其他安卓项目工程之中!

    公司,想优化掉,在app中,以webview方式,加载游戏的方式。以安卓项目为例,改成:游戏项目导出安卓工程,可直接使用的aar资源。 安装配置原生开发环境,可以参考官方文档:https://docs.cocos.com/creator/2.4/manual/zh/publish/setup-native-development.html 备注:本人使用cocoscreator版本为:

    2024年02月05日
    浏览(36)
  • 《入门级-Cocos2dx4.0 塔防游戏开发》---第六课:欢迎界面开发(四、自定义精灵)

    目录  一、开发环境 二、开发内容 2. 1 新建自定义精灵 2.2 在welcome中创建新的menu 2.3 消息绑定以及消息响应 三、演示效果 四、知识点 4.1 内部消息响应 4.2 字体精灵说明 4.3 CC_SYNTHESIZE宏 操作系统:UOS1060专业版本。 cocos2dx:版本4.0 环境搭建教程:统信UOS下配置安装cocos2dx开发

    2024年02月11日
    浏览(28)
  • Pygame和Cocos2d

    Pygame和Cocos2d都是 Python 中常用的游戏引擎,但它们的设计目标、特点和使用场景略有不同。 Pygame与Cocos2d,目前是使用人数最多的两个Python游戏库。根据某知名产品点评网站的数据显示,Cocos2d排名第一,Pygame排名第二。 Pygame是一种基于SDL(Simple DirectMedia Layer)的Python库,主要

    2024年01月21日
    浏览(32)
  • cocos2D插件转3D插件

    cocos2D插件转3D插件

    2024年02月16日
    浏览(32)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包