【问题标题】:EaselJS StageGL: text not working (but does using Stage canvas)EaselJS StageGL:文本不起作用(但使用舞台画布)
【发布时间】:2018-07-12 18:38:19
【问题描述】:

我重新编写了一个 HTML5 游戏(使用 createJS)以匹配 StageGL,但结果所有文本字段都消失了。切换回 Stage 解决了这个特定问题(参见下面的代码示例)。 有人知道解决方法吗?

示例代码:

  canvas.width = stageWidth;
  canvas.height = stageHeight;

  stage = new createjs.StageGL(canvas); // <= text does not work with GL???
  stage = new createjs.Stage(canvas); // <= text works fine

  var textTest = new createjs.Text("Hello World");
  textTest.x = 10;
  textTest.y = 20;

  stage.addChild(textTest);

提前感谢您的 cmets!

【问题讨论】:

    标签: text html5-canvas createjs easeljs


    【解决方案1】:

    如果没有缓存,文本将无法工作,因为 StageGL 不支持文本/矢量画布 API。

    缓存非常简单:

    var bounds = text.getBounds();
    text.cache(bounds.x, bounds.y, bounds.width, bounds.height);
    

    当文本发生变化时,您需要重新缓存文本。

    干杯,

    【讨论】:

    • 很高兴听到。随意接受答案,以便其他人知道问题已解决。
    猜你喜欢
    • 1970-01-01
    • 2014-07-01
    • 1970-01-01
    • 2014-03-02
    • 2016-04-30
    • 1970-01-01
    • 2016-10-01
    • 2014-01-01
    • 2022-01-17
    相关资源
    最近更新 更多