浅谈利用缓存来优化HTML5 Canvas程序的性能

2019-01-28 16:25:23于海丽
  •                 this.useCache = useCache;                    if(useCache){   
  •                     this.cache();                    }   
  •             }      
  •             function getZ(num){                    var rounded;   
  •                 rounded = (0.5 + num) | 0;                    // A double bitwise not.   
  •                 rounded = ~~ (0.5 + num);                    // Finally, a left bitwise shift.   
  •                 rounded = (0.5 + num) << 0;      
  •                 return rounded;                }   
  •                ball.prototype = {   
  •                 paint:function(ctx){                        if(!this.useCache){   
  •                         ctx.save();                            var j=0;   
  •                         ctx.lineWidth = borderWidth;                            for(var i=1;i<this.r;i+=borderWidth){