課程
/前端開發(fā)
/HTML/CSS
/HTML5小游戲---愛心魚(上)
魚不跟隨鼠標(biāo)動(dòng) 而且魚也不在屏幕中間 跟視頻上一樣的代碼 沒有報(bào)錯(cuò) 不知道怎么解決
2015-12-08
源自:HTML5小游戲---愛心魚(上) 2-8
正在回答
var momObj = function(){ ? ?this.x; ? ?this.y; ? ?this.angle; ? ?this.bigEye = new Image(); ? ?this.bigBody = new Image(); ? ?this.bigTail = new Image();}momObj.prototype.init = function(){ ? ?this.x = canWidth*0.5; ? ?this.y = canHeight*0.5; ? ?this.angle = 0; ? ?this.bigEye.src = "./src/bigEye0.png"; ? ?this.bigBody.src = "./src/bigSwim0.png"; ? ?this.bigTail.src = "./src/bigTail0.png";}momObj.prototype.draw = function(){ ? ?//lerp x,y ? ?this.x = lerpDistance(mx,this.x,0.98); ? ?this.y = lerpDistance(my,this.y,0.98); ? ?//delta angle ? ?//Math.atan2(y,x) ? ?var deltaY = my-this.y; ? ?var deltaX = mx-this.x; ? ?var beta = Math.atan2(deltaY,deltaX)+Math.PI; ? ?//lerp angle ? ?this.angle = lerpAngle(beta,this.angle,0.6); ? ?ctx1.save(); ? ?ctx1.translate(this.x,this.y); ? ?ctx1.rotate(this.angle); ? ?ctx1.drawImage(this.bigTail,-this.bigTail.width*0.5+30,-this.bigTail.height*0.5); ? ?ctx1.drawImage(this.bigBody,-this.bigBody.width*0.5,-this.bigBody.height*0.5); ? ?ctx1.drawImage(this.bigEye,-this.bigEye.width*0.5,-this.bigEye.height*0.5); ? ?ctx1.restore();}
慕萊塢9220042
中午晚上吃啥 提問者 回復(fù) 慕萊塢9220042
慕萊塢9220042 回復(fù) 中午晚上吃啥 提問者
sofa 回復(fù) 中午晚上吃啥 提問者
嘴角殘留smile 回復(fù) 中午晚上吃啥 提問者
慕粉3451677 回復(fù) 中午晚上吃啥 提問者
你好,把代碼貼出來(lái)看看。
中午晚上吃啥 提問者
舉報(bào)
學(xué)做HTML5游戲,輕輕松松帶你上手,適合剛?cè)胧钟螒蜷_發(fā)的同學(xué)
2 回答我的魚為什么出不來(lái)啊,哭哭qwq
1 回答為什么鼠標(biāo)移動(dòng)的時(shí)候大小魚消失了???
1 回答我的魚不動(dòng)呀
2 回答為什么是大魚的尾巴跟著鼠標(biāo)移動(dòng)?
1 回答大魚的移動(dòng)
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購(gòu)課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2015-12-09
var momObj = function(){
? ?this.x;
? ?this.y;
? ?this.angle;
? ?this.bigEye = new Image();
? ?this.bigBody = new Image();
? ?this.bigTail = new Image();
}
momObj.prototype.init = function(){
? ?this.x = canWidth*0.5;
? ?this.y = canHeight*0.5;
? ?this.angle = 0;
? ?this.bigEye.src = "./src/bigEye0.png";
? ?this.bigBody.src = "./src/bigSwim0.png";
? ?this.bigTail.src = "./src/bigTail0.png";
}
momObj.prototype.draw = function(){
? ?//lerp x,y
? ?this.x = lerpDistance(mx,this.x,0.98);
? ?this.y = lerpDistance(my,this.y,0.98);
? ?//delta angle
? ?//Math.atan2(y,x)
? ?var deltaY = my-this.y;
? ?var deltaX = mx-this.x;
? ?var beta = Math.atan2(deltaY,deltaX)+Math.PI;
? ?//lerp angle
? ?this.angle = lerpAngle(beta,this.angle,0.6);
? ?ctx1.save();
? ?ctx1.translate(this.x,this.y);
? ?ctx1.rotate(this.angle);
? ?ctx1.drawImage(this.bigTail,-this.bigTail.width*0.5+30,-this.bigTail.height*0.5);
? ?ctx1.drawImage(this.bigBody,-this.bigBody.width*0.5,-this.bigBody.height*0.5);
? ?ctx1.drawImage(this.bigEye,-this.bigEye.width*0.5,-this.bigEye.height*0.5);
? ?ctx1.restore();
}
2015-12-08
你好,把代碼貼出來(lái)看看。