JavaScript
CreateJS
localStorage

LocalStorageを試してみた

More than 1 year has passed since last update.

LocalStorage | CreateJS
ひよこちゃんの位置を記録するよ。
もう一度アクセスし直すと、そのことが確認できるはず。

var piyo = new lib.Piyo();
stage.addChild(piyo);
var position = getPosition();
piyo.x = position.x;
piyo.y = position.y;

function getPosition() {
    var position = {x: canvas.width/2, y: 210};
    if (localStorage.position) {
        position = JSON.parse(localStorage.position);
    }
    return position;
}
function setPosition(px, py) {
    var position = JSON.stringify({x: px, y: py});
    localStorage.position = position;
}