我的代码效果有个bug,连续吃新果实时,旧涟漪会突然消失,新涟漪按规划变大,请问怎么解决?
var waveObj = function () {
this.x = [];
this.y = [];
this.alive = [];
this.r = [];
}
waveObj.prototype.num = 10;
waveObj.prototype.init = function(){
for (var i = 0; i < this.num; i++) {
this.alive[i] = false;
this.r[i] = 0;
}
};
waveObj.prototype.draw = function(){
cxt1.save();
cxt1.lineWidth = 2;
cxt1.shadowBlur = 10;
cxt1.shadowColor = "#fff";
for (var i = 0; i < this.num; i++) {
if (!this.alive[i]) {
this.r[i] += deltaTime*0.04;
if (this.r[i]>50) {
this.alive[i] = false;
continue;
}
var alpha = 1 - this.r[i]/50;
cxt1.beginPath();
cxt1.arc(this.x[i],this.y[i],this.r[i],0,Math.PI*2);
cxt1.closePath();
cxt1.strokeStyle = "rgba(255,255,255,"+alpha+")";
cxt1.stroke();
}
}
cxt1.restore();
}
waveObj.prototype.born = function(x,y){
for (var i = 0; i < this.num; i++) {
if (!this.alive[i]) {
this.alive = true;
this.r[i] = 10;
this.x[i] = x;
this.y[i] = y;
return;
}
}
}其他都好着,编译也不会出现问题。就是这样的涟漪就像突然消失一样,很不好,不知道怎么解决。