使用javascript localstorage存储和加载数据?
我正在用javascript制作一个简单的游戏,我感兴趣的是使用localstorage存储和加载分数,而不是刷新后重置 当前代码:使用javascript localstorage存储和加载数据?,javascript,html5-canvas,local-storage,Javascript,Html5 Canvas,Local Storage,我正在用javascript制作一个简单的游戏,我感兴趣的是使用localstorage存储和加载分数,而不是刷新后重置 当前代码: var points = 0; if ( hero.x <= (monster.x + 30) && monster.x <= (hero.x + 30) && hero.y <= (monster.y + 30) && mons
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;
}
var点=0;
如果(
hero.x您要查找的是:localStorage.setItem(“points”,localStorage.getItem(“points”)+1);
建议使用set/get方法而不是直接属性访问,但不是必需的。
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;
}