繪制??l(fā)光效果時(shí),畫面變得十分不流暢,怎么辦?
我用shadowColor和shadowBlur來(lái)增加??陌l(fā)光效果,但加上后游戲性能出現(xiàn)了很大的問(wèn)題,畫面不流暢。為了把海葵發(fā)光效果設(shè)置提到循環(huán)外,嘗試另開(kāi)一個(gè)canvas畫海葵,但還是很卡。不知道有沒(méi)有人做??男Ч?,關(guān)于這個(gè)問(wèn)題有沒(méi)有什么解決思路呢?
附 Ane的draw方法
AneObj.prototype.draw = function ?() {
ctx2.save();
ctx2.globalAlpha = 0.6 ;
ctx2.strokeStyle = "#3b154e";
ctx2.lineCap = "round";
ctx2.lineWidth = 20;
// ctx2.shadowColor = "#fff";
// ctx2.shadowBlur = 3;
this.alpha += deltaTime * 0.0015;
var l = Math.sin(this.alpha);
for (var i = this.num; i > 0; i--) {
ctx2.beginPath();
ctx2.moveTo(this.rootx[i], can_h);
this.headx[i] = this.rootx[i] + l * this.amp[i];
ctx2.quadraticCurveTo(this.rootx[i], this.heady[i]+50 ,this.headx[i] , this.heady[i]);
ctx2.stroke();
};
ctx2.restore();
};
2016-10-11
for(var i=0; i<this.num; i++){
if(this.alive[i]){
//draw
this.r[i] += deltaTime*0.04;
if(this.r[i]>50){
this.alive[i] = false;
continue;
}
var alpha = 1 - this.r[i]/50;
ctx1.beginPath();
ctx1.arc(this.x[i], this.y[i], this.r[i], 0, Math.PI*2);
ctx1.closePath();
ctx1.strokeStyle = "rgba(255, 255, 255,"+ alpha +")";
ctx1.stroke();
}
}