更新イベントを登録する
// グローバルに展開
phina.globalize();
// メインシーン
phina.define("MainScene", {
// 継承
superClass: 'DisplayScene',
//初期化
init: function () {
//親クラス初期化
this.superInit();
//背景色
this.backgroundColor = 'lightgrey';
// Shapeを作成してシーンに追加
var shape = Shape().addChildTo(this).setPosition(320, 480);
//毎フレーム更新処理
shape.on('enterframe', function () {
//移動
shape.moveBy(1, 1);
});
//毎フレーム更新処理
shape.on('enterframe', function () {
//回転
shape.rotation++;
});
},
});
//メイン処理
phina.main(function () {
// アプリケーションを生成
var app = GameApp({
// MainSceneから開始
startLabel: 'main',
});
// fps表示
//app.enableStats();
//実行
app.run();
});
update関数を使うと、毎フレーム更新処理が行われる。
また、update関数では1つのメソッドしか登録できない。
▷更新イベント処理(複数)
//毎フレーム更新処理
shape.on('enterframe', function () {
//移動
shape.moveBy(1, 1);
});
//毎フレーム更新処理
shape.on('enterframe', function () {
//回転
shape.rotation++;
});
onとenterframeを組み合わせると、複数のメソッドを登録することが可能。
イベントを並行して実行することができる。