0
我在javascript中做了一個簡單的遊戲,我有興趣使用localstorage存儲和加載分數,而不是在刷新後重置。使用javascript localstorage存儲和加載數據?
當前代碼:
var points = 0;
if (
hero.x <= (monster.x + 30)
&& monster.x <= (hero.x + 30)
&& hero.y <= (monster.y + 30)
&& monster.y <= (hero.y + 30)
) {
++points;
}
我的存儲點應該是這樣的最終結果,但我不能完全弄清楚:
if (
hero.x <= (monster.x + 30)
&& monster.x <= (hero.x + 30)
&& hero.y <= (monster.y + 30)
&& monster.y <= (hero.y + 30)
) {
localStorage.points=Number(localStorage.points)+1;
}
else
{
localStorage.points=0;
}
我到底做錯了什麼?
使用set/get方法,建議在直接訪問屬性,但不是必需的。 – jbabey 2013-03-04 14:40:28