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