canvas中写了一段粒子动画。通过点击事件触发;第二次触发动画就闪动开了怎么回事
function arrow(canvas,obj,posArr,colorArr,animateArr) { //canvas和2d对象 this.canvas=canvas; this.obj=obj; //固定位置(起始点,结束点) this.grapos=animateArr?animateArr[0]:0.2; //渐变起始点 this.speed=animateArr?animateArr[1]:0.05; //控制动画的速度 this.num=50;//控制动画的时长 this.flag=true;//动画的开关 //绘制箭头的点坐标 this.pos1_x=posArr[0];//上曲线起点坐标 **************渐变起点************************* this.pos1_y=posArr[1]; this.pos2_x=posArr[2];//控制点1的坐标 this.pos2_y=posArr[3]; this.pos3_x=posArr[4];//上曲线终点坐标 this.pos3_y=posArr[5]; //箭头三角的坐标 this.pos4_x=posArr[6]; this.pos4_y=posArr[7]; this.pos5_x=posArr[8];// ********************渐变终点********************** this.pos5_y=posArr[9]; this.pos6_x=posArr[10]; this.pos6_y=posArr[11]; //下曲线起点坐标 this.pos7_x=posArr[12]; this.pos7_y=posArr[13]; //下曲线控制点坐标 this.pos8_x=posArr[14]; this.pos8_y=posArr[15]; //渐变的颜色设置 this.beginColor=colorArr?colorArr[0]:"rgba(255,255,255,0)"; this.moveColor=colorArr?colorArr[1]:"rgba(33,126,216,0.5)"; this.endColor=colorArr?colorArr[2]:"rgba(33,126,216,1)"; } arrow.prototype={ draw:function () { var gra=this.obj.createLinearGradient(this.pos1_x,this.pos1_y,this.pos6_x,this.pos6_y); gra.addColorStop(0, this.beginColor); gra.addColorStop(this.grapos, this.moveColor); gra.addColorStop(1, this.endColor) //上曲线 this.obj.beginPath(); this.obj.moveTo(this.pos1_x, this.pos1_y); //箭头尾部(起始点) this.obj.quadraticCurveTo(this.pos2_x, this.pos2_y, this.pos3_x, this.pos3_y); //绘制上曲线 //三角 //this.obj.lineTo(225, 120); this.obj.lineTo(this.pos4_x, this.pos4_y); this.obj.lineTo(this.pos5_x, this.pos5_y); this.obj.lineTo(this.pos6_x, this.pos6_y); this.obj.lineTo(this.pos7_x, this.pos7_y) //下曲线 this.obj.quadraticCurveTo(this.pos8_x, this.pos8_y, this.pos1_x, this.pos1_y); this.obj.fillStyle = gra; this.obj.fill(); }, //动画 play:function () { this.flag=false; var that=this; var t1=setInterval(function () { that.num--; if (that.num<=0){ clearInterval(t1); that.obj.clearRect(0,0,1000,1000); that.flag=true; that.num=50; return; } if (that.grapos > 0.9) { that.grapos = 0.2; } else { that.grapos += that.speed; } that.obj.clearRect(0,0,1000,1000) that.draw(); },100) }, //清空画布操作 clearAll:function () { this.obj.clearRect(0,0,1000,1000); } }
代码贴出来看一下
我站出来了,一个渐变的箭头动画。不同的事件可以画出不一样的箭头动画,但是如果多次点击会闪。开关也许加的地方不对,也没什么反应
这只是具有相同问题的例子。原动画有点不方便
一般也不同时触发,没人不解决了
想看下效果图是怎样的
实际的效果图在上传了,有兴趣可以看下(不是上面代码的运行结果,不过具有相同的闪动问题)
你的问题需要什么样的效果图?现在做的效果图又是怎样的?
就是在canvas中不断画出一些粒子构成一个曲线的运动轨迹。当触发一个事件时去执行他。目前的问题是如果这段粒子没有运动完再次触发的话 ,动画效果会闪动
我实际代码(不是贴出来的代码,但是问题都一样)的运行效果图上传了,其中红色的就是一些圆形粒子生成的。