WEB开发网
开发学院网页设计JavaScript Canvas性能技巧:必须知道的Canvas性能技巧 阅读

Canvas性能技巧:必须知道的Canvas性能技巧

 2012-03-30 10:21:26 来源:WEB开发网   
核心提示: 一.预渲染错误代码: var canvas = document.getElementById("myCanvas"); var context = this.canvas.getContext('2d'); var drawAsync = eval(Jscex.compil

 一.预渲染

错误代码:

    var canvas = document.getElementById("myCanvas");
    var context = this.canvas.getContext('2d');
    var drawAsync = eval(Jscex.compile("async", function () {
      while (true) {
        drawMario(context);
        $await(Jscex.Async.sleep(1000));
      }
    }))
    drawAsync().start();
正确代码:

    var canvas = document.getElementById("myCanvas");
    var context = this.canvas.getContext('2d');
    var m_canvas = document.createElement('canvas');
    m_canvas.width = 64;
    m_canvas.height = 64;
    var m_context = m_canvas.getContext('2d');
    drawMario(m_context);
    var drawAsync = eval(Jscex.compile("async", function () {
      while (true) {
        context.drawImage(m_canvas, 0, 0);
        $await(Jscex.Async.sleep(1000));
      }
    }))
    drawAsync().start();
这里m_canvas的宽度和高度控制得越小越好。

1 2 3 4  下一页

Tags:Canvas 性能 技巧

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接