JavaScript文件借用了 CodePen ,非常感谢Jason(jsndks)。
我的绘制功能已被编辑,因此注释掉了部分:
proto.draw = function() {
var img = new Image();
if (!this.context) {
return;
}
this.context.clearRect(0, 0, this.canvasWidth, this.canvasHeight);
//this.context.strokeStyle = PARTICLE_COLOR;
for(var i= 0; i < PARTICLE_QUANT; i++) {
//img.src = 'http://www.clipartbest.com/cliparts/nTX/b6R/nTXb6RqTB.png';
if (i%2 == 0){
img.src = 'http://www.clipartbest.com/cliparts/nTX/b6R/nTXb6RqTB.png';
}else {
img.src = 'http://www.clker.com/cliparts/q/j/I/0/8/d/green-circle-icon-hi.png';
}
var particle = this.particles[i];
//this.context.save();
//this.context.beginPath();
////this.context.arc(particle.x, particle.y, ARC_RADIUS, 0, Math.PI * 2);
//this.context.stroke();
//this.context.restore();
this.context.drawImage(img, particle.x , particle.y, 20 ,20);
}
};
任何帮助将不胜感激。我的目标是画布局部动画,在场景中漂浮着顽皮和十字架。
非常感谢
答案 0 :(得分:0)
刚从其他来源获得帮助,我所要做的就是移动&#34; var img = new Image();&#34;在for循环中。