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; } } }
其他都好着,编译也不会出现问题。就是这样的涟漪就像突然消失一样,很不好,不知道怎么解决。
还有第39行,alive后面少写了 [i] ,
把我说的这几处都改一下就可以了、、、
第20行代码处,去掉!符号即可。
然后第13行的 ; 符号,建议去掉,一般是不带的。。