
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
不知道你的代碼結(jié)構(gòu)是不是跟視頻里的差不多,視頻里gameloop()這個(gè)函數(shù)一直在循環(huán),而data.js里的draw()一直再被gameloop()調(diào)用,draw()里有score的繪制,因此會(huì)一直被重復(fù)繪制。而你的累加,有可能是因?yàn)轸~(yú)媽媽跟小碰撞檢測(cè)的條件沒(méi)有寫(xiě)清楚。