weibo恋聃纯
2017-04-08 21:00

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;
}
不知道你的代码结构是不是跟视频里的差不多,视频里gameloop()这个函数一直在循环,而data.js里的draw()一直再被gameloop()调用,draw()里有score的绘制,因此会一直被重复绘制。而你的累加,有可能是因为鱼妈妈跟小碰撞检测的条件没有写清楚。
HTML5小游戏---爱心鱼(下)
46270 学习 · 194 问题
相似问题