zoukankan      html  css  js  c++  java
  • 3.4 常用的两种 layer 层 3.7 字体与文本

    3.4 常用的两种 layer 层 

    //在cocos2d-x中,经常使用到的两种 layer 层 : CCLayer 和 CCLayerColor
    
        //CCLayer 的创建
        CCLayer* layer = CCLayer::create();
        
        //CCLayerColor 的创建
        CCLayerColor* layerColor = CCLayerColor::create(const cocos2d::ccColor4B &color); //RGBO
    
        /*
        注意:
        新创建的 CCLayer 和 CCLayerColor 层如果没有手动设置其大小,默认是当前设备的宽高作为 layer 的尺寸
        CCLayer 与 CCLayerColor 虽然默认锚点是 (0.5, 0.5), 坐标(0, 0),但是创建后的层总是充满屏幕的
        */

    3.7 字体与文本

     在使用字体的时候需要注意, CCLabelTTF 每调用 setString 改变显示字符串的时候,一个新
    的OPENGL纹理将会创建。也就意味着调用 setString 函数和创建一个新的文本一样慢。
    ∴ 频繁 更新时 建议尽可能不使用 CCLabelTTF 对象, 考虑使用 CCLabelAtlas 或 CCLabelBMFont.

    //CCLabelTTF 、CCLabelAtlas 、CCLabelBMFont
    
        /*1.CCLabelTTF*/
        CCLabelTTF::create(const char* string, const char* fonName, float fontSize);
        //参数1:需要显示的字符串  参数2:字体名称  参数3:字体大小
        CCLabelTTF::create();
        //默认无参创建,默认使用字体类型 Helvetica
        //常用函数为: setString(const char* label);
    
    
        /*2.CCLabelAtlas*/  
        //常用函数 setString(const char *label);   setColor(const ccColor3B& color)
        CCLabelAtlas::create(const char* string, const char* charMapFile, unsigned int itemWidth, unsigned int itemHeight, unsigned int startCharMap);
        //作用:利用一张字体图片资源来创建一个 CCLabelAtlas 对象
        //参数 1:需要显示的字符串
        //参数 2:文字图片资源名称
        //参数 3:每个文字的宽
        //参数 4:每个文字的高
        //参数 5:字体起始标示
    
        CCLabelAtlas::create(const char* string, const char* fntFile);
        //作用:利用加载字体配置文件,来创建一个 CCLabelAtlas 对象
        //参数 1:需要显示的字符串
        //参数 2:字体配置文件的名称
    
        /*3.CCLabelBMFont*/
        CCLabelBMFont::create(const char* str, const char* fntFile);
        //参数 1:需要显示的文字
        //参数 2:字体资源文件的名称
    
    
        //示例代码
        //---------------CCLabelTTF
        CCLabelTTF* pLabel = CCLabelTTF::create("visionFont", "Thonburi", 24);
    
        CCLabelTTF* pLabel2 = CCLabelTTF::create();
        pLabel2->setFontSize(24);
        pLabel2->setString("visionFont");
    
        //---------------CCLabelAtlas
        CCLabelAtlas* label = CCLabelAtlas::create("visionFontAtlas", "testFont.png", 30, 30, ' ');
        label->setColor(ccc3(255, 0, 0));
    
        CCLabelAtlas* label2 = CCLabelAtlas::create("visionFontAtlas2", "testfont.plist");
        label2->setString("123");
    
        //---------------CCLabelBMFont
        CCLabelBMFont* labelBM = CCLabelBMFont::create("stand up font", "testFont.fnt");
  • 相关阅读:
    数据库的规范和SQL优化技巧总结
    新版Intellij idea破解方法(插件IDE Eval Reset)
    容易遗忘的知识点总结
    Java如何搭建脚手架(自动生成通用代码),创建自定义的archetype(项目模板)
    阿里云服务器域名解析和ICP域名备案
    云服务器通过ip无法访问
    FirewallD is not running 远程服务器开启端口报错
    [prerender-spa-plugin] Unable to prerender all routes! 内网打包报错(Navigation Timeout Exceeded)
    vue-cli中的 mode模式、env环境文件,以及其中定义的环境变量
    绘制柱状图和横向条形图,带数据标签!!!
  • 原文地址:https://www.cnblogs.com/MrGreen/p/3428560.html
Copyright © 2011-2022 走看看