• cocosbuilder中使用字体描边时,字符重叠,间距过小问题


    cocosbuilder中使用字体描边时,字符重叠,间距过小问题

    cocos2d-x 3.7


    v3.7解析cocosbuilder中描边字体的代码如下:

    void LabelTTFLoader::parseProperties( cocos2d::Node * pNode, cocos2d::Node * pParent, CCBReader * ccbReader )
    {
    	_enableOutline = false;
    	_enableShadow = false;
    	NodeLoader::parseProperties(pNode, pParent, ccbReader);
    	auto label = (Label *)pNode; 
    	int outlineSize = _enableOutline ? 1 : 0;
    	label->setTTFConfig(TTFConfig(label->getSystemFontName().c_str(), label->getSystemFontSize(), GlyphCollection::DYNAMIC, nullptr, false, outlineSize));
    	if (_enableOutline) {
    		label->enableOutline(Color4B::BLACK);
    		label->setAdditionalKerning(-2); //设置间距
    	}
    	if (_enableShadow) {
    		label->enableShadow(Color4B(0,0,0,180), Size(0.5,-0.5));
    	}
    }
    

    当有字体描边时,enableOutline默认描边时-1,且添加字符间距为-2,这样就会导致字符重叠,间距过小等问题。当显示的文字size很大时,看不出什么,当size很小时,就会看到明显的重叠。如图(top正常描边,bottom重叠):

    两种解决方案:

    1. ccb加载之后,重新调整描边宽度和间距。这种方案,在cocosbuilder布局之后,还需要重新写代码。
    2. 修改加载代码:
    if (_enableOutline) {
    		label->enableOutline(Color4B::BLACK, 1);
    		label->setAdditionalKerning(2);
    	}
    

    让描边默认宽度为1,那么左右各加1间距就应该至少加2才不会挤。当需要更改描边颜色,或宽度时就必须得重新设置了。

  • 相关阅读:
    Pure播放器
    WPF绑定并转换
    WPF的DataTrigger使用
    NancyFx框架之检测任务管理器
    Asp.Net MVC 5使用Identity之简单的注册和登陆
    AspNetCore使用MySQL
    Head First 设计模式之适配器模式与外观模式
    Head First 设计模式之命令模式(CommandPattern)
    Head First 设计模式之工厂模式(Factory Pattern)
    .NET设计规范————类型设计规范
  • 原文地址:https://www.cnblogs.com/songcf/p/4772512.html
Copyright © 2020-2023  润新知