if (typeof localStorage["BestScore"] <= "undefined")
{ var maxScore= localStorage["BestScore"] }
} else localStorage["BestScore"] = 0;
var maxScore=0;
var newScore=false
function drawScore(score) {
if (newScore == true && score < maxScore) {
newScore = false;
}
if (score > maxScore) {
newScore = true;
localStorage["BestScore"] = score;
if ([5, 10, 15, 20].indexOf(score) !== -1) {
play(sndMedal);
} else {
play(sndGain);
}
}
maxScore = Math.max(score, maxScore);
ctx.drawImage(sheet, 146, 58, 113, 58,
-226, 0, 226, 116);
ctx.save();
ctx.translate(-20, 45);
ctx.scale(0.5, 0.5);
var size = drawNbr(score, false);
ctx.restore();
// var draw medals
ctx.save();
ctx.translate(-178, 66);
if (score >= 20) { // platinum
ctx.drawImage(sheet,220, 144, 22, 22, -22, -22, 44, 44);
} else if (score >= 15) { // gold
ctx.drawImage(sheet,242, 229, 22, 22, -22, -22, 44, 44);
} else if (score >= 10) { // silver
ctx.drawImage(sheet,266, 229, 22, 22, -22, -22, 44, 44);
} else if (score >= 5) { // bronze
ctx.drawImage(sheet,302, 137, 22, 22, -22, -22, 44, 44);
}
ctx.restore();
if (newScore) { // draw NEW
ctx.save();
ctx.translate(-60 - (size*16), 37);
ctx.drawImage(sheet, 146, 245, 16, 7,
0, 0, 32, 14);
ctx.restore();
}
ctx.save();
ctx.translate(-20, 88);
ctx.scale(0.5, 0.5);
drawNbr(maxScore, false);
ctx.restore();
이 내가 maxscore있을 때 내가 그것을 실행할 때 발생하는 것입니다 = 로컬 스토리지 [imageshack.com/ 작동하지 않습니다 a/img691/167/28x1.png] [1] 그리고 동결되었습니다.
이 코드는 로컬 저장소의 최고 점수가 이고 값이 정의되지 않았는지 확인하려고 시도하고 값을 갖는 경우 maxscore를 0으로 설정하면 maxscore를 값으로 설정합니다. 어떤 이유로이 코드는 작업을 도와주지 않습니다. [1]
받은 스 니펫은 완벽합니다. 다른 곳에서 오류를 찾으십시오. – sabof
maxScore 변수가 지역 변수 인 이유는 무엇입니까? –