LoginSignup
1
1

More than 5 years have passed since last update.

LocalStorageを試してみた

Last updated at Posted at 2017-11-27

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;
}
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1