LoginSignup
11
11

More than 5 years have passed since last update.

jsでシーン管理するライブラリつくったよ

Posted at

================================
内容薄いですがとりあえず共有

元Flasherには馴染みのある、シーン管理の概念をjavascriptに導入する。
まだ低機能ですが、既にHTMLコンテンツや他のJSゲーム系アプリで利用してます。

github
ソース

HTMLサンプル
※Chromeのみ確認済

機能

urlライクな"シーンパス"と、それに紐づく"シーン"の組み合わせと、遷移を管理する。

使い方

// "/"シーンの定義
Scene.add("/").set({
    onShow: function(){ console.log("/ 表示処理"); },
    onHide: function(){ console.log("/ 非表示処理"); }
});
// "/scene1"シーンの定義
Scene.add("/scene1").set({
    onEnter: function(){ console.log("/scene1以下に影響する処理"); },
});
// "/scene1/child"シーンの定義
Scene.add("/scene1/child").set({
    onShow: function(){ console.log("/scene1 表示処理"); },
    onHide: function(){ console.log("/scene1 非表示処理"); }
});

// "/"へ遷移
Scene.goto("/");

// 1秒後に"/scene1/child"へ遷移
setTimeout( function(){ Scene.goto("/scene1/child"); }, 1000 );

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