亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

score 打印在canvas時當檢測到碰撞時,score 會重復畫,一直累加為什么會這樣?求解答

http://img1.sycdn.imooc.com//58e8de7f0001d83213660768.jpg

var?dataObj=function(){
??this.score=0;
this.ntrNum=0;
this.gameover=false;
}

dataObj.prototype.draw=function(){
??//?var?w=can1.width;
??//?var?h=can1.height;

??ctx1.fillStyle?=?"white";

??//?ctx1.fillText=("score"+this.score,canWidth*0.5,canHeight/12);
????ctx1.fillText("score??"+this.score,canWidth*.5,canHeight-20);
????ctx1.fillText("ntrNUm??"+this.ntrNum,canWidth*.5,canHeight-50);

console.log(this.score)

}

??dataObj.prototype.addScore=function(){
????//?if(this.ntrNum>0){
??????this.score+=this.ntrNum*10;
????//?}
????this.ntrNum=0;

??}


正在回答

1 回答

不知道你的代碼結構是不是跟視頻里的差不多,視頻里gameloop()這個函數一直在循環,而data.js里的draw()一直再被gameloop()調用,draw()里有score的繪制,因此會一直被重復繪制。而你的累加,有可能是因為魚媽媽跟小碰撞檢測的條件沒有寫清楚。

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

score 打印在canvas時當檢測到碰撞時,score 會重復畫,一直累加為什么會這樣?求解答

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號