【乐府】突破Label的缓存模式(2)-CHAR的无限模式

可以在chrome中添加一个 SpectorJS插件,就能看到生成的纹理图

为啥我看到生成的纹理图好模糊?看不清上面的字

大佬,可以贴一下工程代码吗?

Mark

兄弟你弄出来了吗

没有弄鸭

可以将demo放出来吗?

兄弟你搞出来没?

大兄弟你搞出来没?

replaceLetterTexture 里面记得给xAdvance赋值 oldLetter.xAdvance = oldLetter.w;
如果不赋值的话 在bmfont.js中进行排版会拿上一个大的char图去横向排版,中间会有间隔

replaceLetterTexture(oldLetter, letterTexture, char) {

    let oldHash = oldLetter.hash;

    let texture = letterTexture._texture;

    this._fontDefDictionary._texture.drawTextureAt(texture, oldLetter.u - bleed / 2, oldLetter.v - bleed / 2);

    oldLetter.hash = letterTexture._hash;

    oldLetter.w = letterTexture._width - bleed;

    oldLetter.h = letterTexture._height - bleed;

    oldLetter.xAdvance = oldLetter.w;

    oldLetter.offsetY = letterTexture._offsetY;

    oldLetter.refCount = 0;

    this._dirty = true;

    this._fontDefDictionary.addLetterDefinitions(letterTexture._hash, oldLetter);

    this._fontDefDictionary._letterDefinitions[oldHash] = null;

    return oldLetter;

}
1赞

mark.

这套方法在最新版本的creator能 使用么

牛逼!!!

Mark!

image
3.6.1版本在h5上跑没问题,在安卓上跑会变色,这一步的作用是什么,3.6.1好像没有这个类

版本问题,这个帖子已经解决。

补充两个问题:

  1. 在回收字符时,向_unusedLetterListpush的时候,要先判断_unusedLetterList中已经存在回收的letter,否则在Label频繁更新的时候,容易造成内存泄露
  2. 在切换场景时,系统会重建图集,所以需要在letter-font.js的clearAllCache中将_unusedLetterListpush清空
4赞

没看到哪里加,回收字符的代码。

spector js 显示的图只有256*256,看不清楚。

自己创建一个spriteFrame ,然后把 labeltexture 赋值给他 ,自己在显示sprite 就可以看了