LoginSignup
0
0

More than 3 years have passed since last update.

P5.js 日本語リファレンス(storeItem)

Last updated at Posted at 2020-05-20

このページでは「P5.js 日本語リファレンス」 の storeItem関数を説明します。

storeItem()

説明文

キー名でローカルストレージに値を格納します。キーは変数の名前にすることができますが、そうである必要はありません。保存されたアイテムを取得するには getItem() を使用してください。

ローカルストレージとは、ブラウザに保存され、ブラウジングセッションとページの再読み込みの間も保持されているものです。

パスワードや個人情報などの機密データはローカルストレージに保存しないでください。

構文

storeItem(key, value)

パラメタ

  • key

    String:キー名

  • value

    String | Number | Object | Boolean | p5.Color | p5.Vector:保存する値

// キャンバスの中心にキー入力した文字を表示します
// ページをリロードすると最後に入力した文字を再表示します
// (最後に入力した文字はローカルストレージに保存してあるため)
let myText;

function setup()  {
  createCanvas(100, 100);
  myText = getItem('val');

  // val にはまだ一度も保存していないので NULL になっている
  if (myText === null) {
    myText = '';
  }
 }

function draw()  {
   textSize(40);
   background(255);
   text(myText, width / 2, height / 2);
 }

function keyPressed()  {
   myText = key; // 入力したキー(文字)の内容を myText に代入
   storeItem('val', myText); //  myText の値をローカルストレージに保存
 }

実行結果

著作権

p5.js was created by Lauren McCarthy and is developed by a community of collaborators, with support from the Processing Foundation and NYU ITP. Identity and graphic design by Jerel Johnson.

ライセンス

Creative Commons(CC BY-NC-SA 4.0) に従います。

0
0
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
0
0