老師,為什么rotate方法使用后,魚的位置不跟著鼠標(biāo)光標(biāo)移動(dòng)了,畫布旋轉(zhuǎn),坐標(biāo)系也旋轉(zhuǎn)了嗎??
momObj.prototype.draw = function(){
? ?var deltaY=my-this.y;
? ?var deltaX=mx-this.x;
? ?var beta = Math.atan2(deltaY,deltaX);
? ?//console.log(beta);
? ?//this.x=this.x*Math.cos(this.lastbeta-beta)+this.x*Math.sin(this.lastbeta-beta);
? ?//this.y=this.y*Math.sin(this.lastbeta-beta)+this.y*Math.cos(this.lastbeta-beta);
? ?//beta=Math.PI/2;
? ?//var mmx=mx*Math.cos(-beta)+my*Math.sin(-beta);
? ?//var mmy=mx*Math.sin(-beta)+my*Math.cos(-beta);
? ?this.x = lerpDistance(mx,this.x,0.9);
? ?this.y = lerpDistance(my,this.y,0.9);
? ?this.angle = lerpAngle(beta,this.angle,0.9);
? ?console.log(this.angle);
? ?ctx1.save();
? ?ctx1.translate(canWidth*0.5,canHeight*0.5);
? ?ctx1.rotate(this.angle);
? ?ctx1.drawImage(this.body,this.x-this.body.width*0.5,this.y-this.body.height*0.5);
? ?ctx1.drawImage(this.eye,this.x-this.eye.width*0.5,this.y-this.eye.height*0.5);
? ?ctx1.drawImage(this.tail,this.x-this.tail.width*0.5+30,this.y-this.tail.height*0.5);
? ?//this.lastbeta=beta;
? ?ctx1.restore();
}
2016-04-20
我還想不明白,跟你一樣的問題
2016-03-06
我想通了,哈哈,還是要分解問題,多看老師的編程思路才能衍生出自己的。不用大家給我回答了,