我正在用javascript做一个简单的游戏,我感兴趣的是用本地存储来存储和加载分数,而不是在刷新后重新设置它。
当前代码:
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;
}我做错了什么?
发布于 2013-03-04 22:38:21
你要找的是:localStorage.setItem("points", localStorage.getItem("points")+1);
https://stackoverflow.com/questions/15203968
复制相似问题