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