【问题标题】:gwt canvas context.drawImage very slowgwt canvas context.drawImage 很慢
【发布时间】:2013-07-23 07:39:17
【问题描述】:

我正在使用 GWT 画布用 requestAnimationFrame 全屏绘制 50 个相同的 16x16 图像(在 draw() 中),主循环如下:

AnimationScheduler.get().requestAnimationFrame(new AnimationCallback() {
                    public void execute(double timestamp) {
                        mainLoop(deltaTimeInMs);
                        AnimationScheduler.get().requestAnimationFrame(this,canvasElem);
                    }
                }, canvasElem);


void mainLoop(double deltaTime) {
        calcFPS(deltaTime);
        clearContext();
        update(deltaTime);
        draw();
}

我使用ClientBundle 将图像存储为DataResources。它们被转换为图像和ImageElement 以便能够调用 context.draw。

渲染 50 张图像之前的 FPS 约为 60FPS。当它们被渲染时,FPS 大约是 20FPS。 (在 chrome 和 mozilla 中)在 DEV 模式下。

我认为图像加载可能有问题。

【问题讨论】:

  • 运行如此缓慢的原因是 DEV 模式。在 GWT 2.5+ 版本中,它在 SDM(超级开发模式)上运行良好。

标签: gwt canvas image-loading requestanimationframe


【解决方案1】:
AnimationScheduler.get().requestAnimationFrame(new AnimationCallback() {
                    public void execute(double timestamp) {
                        mainLoop(deltaTimeInMs);
                        AnimationScheduler.get().requestAnimationFrame(this,canvasElem);
                    }
                }, canvasElem);


void mainLoop(double deltaTime) {
        calcFPS(deltaTime);
        clearContext();
        update(deltaTime);

【讨论】:

  • 您愿意为您的解决方案添加一些解释吗?为什么它比原来的问题快?它更快吗?
  • 这是一个巨魔答案......他刚刚删除了 draw() 调用。请对此投反对票
猜你喜欢
  • 2015-06-20
  • 1970-01-01
  • 2014-09-11
  • 2015-12-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-14
  • 1970-01-01
相关资源
最近更新 更多