美文网首页
NGUI字体描边

NGUI字体描边

作者: Anil | 来源:发表于2017-04-16 18:06 被阅读0次

    NGUI的UILabel中实现字体的描边是通过以方形的方式对字体网格顶点偏移一定位置后作为其描边网格。以这种方式描边在边角处会生硬,描边不均匀问题,特别是在比较大的字体描边时偏移越大这种生硬,不均匀程度越明显。处理这种描边一可以通过改进shader的方式来做调整,这里我介绍林一种新的方式:以圆形方式对字体网格顶点偏移一定位置后作为其描边网格。

    具体修改是将UILabel 中的OnFill方法中:

    //Applyaneffectifonewasrequested

    if(effectStyle!=Effect.None)

    {

    intend=verts.size;

    pos.x=mEffectDistance.x;

    pos.y=mEffectDistance.y;

    ApplyShadow(verts,uvs,cols,offset,end,pos.x,-pos.y);

    if(effectStyle==Effect.Outline)

    {

    offset=end;

    end=verts.size;

    ApplyShadow(verts,uvs,cols,offset,end,-pos.x,pos.y);

    offset=end;

    end=verts.size;

    ApplyShadow(verts,uvs,cols,offset,end,pos.x,pos.y);

    offset=end;

    end=verts.size;

    ApplyShadow(verts,uvs,cols,offset,end,-pos.x,-pos.y);

    }

    }

    替换为如下代码:

    //Applyaneffectifonewasrequested

    if(effectStyle!=Effect.None)

    {

    intend=verts.size;

    pos.x=mEffectDistance.x;

    pos.y=mEffectDistance.y;

    if(effectStyle!=Effect.Outline)

    ApplyShadow(verts,uvs,cols,offset,end,pos.x,-pos.y);

    else{

    floatarcLength=1.4142f;

    floatdr=1f;

    floatr=pos.x;

    floatradian=arcLength/r;

    floattempR=0;

    while(tempR

    intcount=(int)Math.Floor(Math.PI*2/radian);

    floati=0;

    while(i

    floatangle=radian*i;

    floatx=tempR*(float)Math.Cos((double)angle);

    floaty=tempR*(float)Math.Sin((double)angle);

    ApplyShadow(verts,uvs,cols,offset,end,x,y);

    offset=end;

    end=verts.size;

    ++i;

    }

    tempR+=dr;

    }

    }

    }

    最后的效果对比如下:

    图一

    图一(调整后的效果)

    图二

    图二(调整前的效果)

    圆形拓展网格对比方形扩展网格缺点就是圆形拓展方式获得新网格会比矩形多,具体增加的量与描边偏移量有一定关系,同时目前暂时不支持x和y的不同偏移,只支持x与y的统一偏移量。

    本文来自我的腾讯开发者博客:http://gad.qq.com/college/articledetail/7172155

    相关文章

      网友评论

          本文标题:NGUI字体描边

          本文链接:https://www.haomeiwen.com/subject/fsgaattx.html