使用分层画布来优化HTML5渲染的教程

2020-04-24 19:34:57易采站长站整理

     *    
     * @param {number} x   
     * @param {number} y   
     * @param {number} width   
     * @param {number} height   
     */   
    this.addDirtyRect = function(x, y, width, height) {   
        // Calculate out the rectangle edges   
        var left   = x;   
        var right  = x + width;   
        var top    = y;   
        var bottom = y + height;   
    
        // Min of left and entity left   
        this.left   = left < this.left      left   : this.left;   
        // Max of right and entity right   
        this.right  = right > this.right    right  : this.right;   
        // Min of top and entity top   
        this.top    = top < this.top        top    : this.top;   
        // Max of bottom and entity bottom   
        this.bottom = bottom > this.bottom  bottom : this.bottom;   
    
        this.isDirty = true;   
    };   
    
    /**   
     * Clears the rectangle area if the manager is dirty   
     *   
     * @param {CanvasRenderingContext2D} context   
     */   
    this.clearRect = function(context) {