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

2020-04-24 18:59:39易采站长站整理

                        this.cacheCtx.beginPath();   
                        thisthis.cacheCtx.strokeStyle = this.color[j];   
                        this.cacheCtx.arc(this.r , this.r , i , 0 , 2*Math.PI);   
                        this.cacheCtx.stroke();   
                        j++;   
                    }   
                    this.cacheCtx.restore();   
                },   
  
                move:function(){   
                    this.x += this.vx;   
                    this.y += this.vy;   
                    if(this.x>(canvas.width-this.r)||this.x<this.r){   
                        thisthis.x=this.x<this.r?this.r:(canvas.width-this.r);   
                        this.vx = -this.vx;   
                    }   
                    if(this.y>(canvas.height-this.r)||this.y<this.r){   
                        thisthis.y=this.y<this.r?this.r:(canvas.height-this.r);