タッチイベントを登録する【Phina.js】

タッチイベントを登録する

// グローバルに展開
phina.globalize();

// メインシーン
phina.define("MainScene", {

  // 継承
  superClass: 'DisplayScene',

  //初期化
  init: function () {
    //親クラス初期化
    this.superInit();
    //背景色
    this.backgroundColor = 'lightgrey';
    // Shapeを作成してシーンに追加
    var shape = Shape().addChildTo(this).setPosition(320, 480);
    //背景色設定
    shape.backgroundColor = 'red';
    //タッチを可能にする
    shape.setInteractive(true);
    //タッチイベント登録
    shape.on('pointstart', function () {
      alert('タッチされました');
    });
    //タッチイベント登録
    shape.on('pointstart', function () {
      shape.backgroundColor = 'blue';
    });
  },
});

//メイン処理

phina.main(function () {
  // アプリケーションを生成
  var app = GameApp({
    // MainSceneから開始
    startLabel: 'main',
  });
  // fps表示
  //app.enableStats();
  //実行
  app.run();
});

 

▷タッチを可能にする

shape.setInteractive(true);

 

▷タッチイベント登録(複数)

shape.on('pointstart', function () {
  alert('タッチされました');
});

 

▷タッチイベント登録(1つ)

shape.onpointstart = function() {
  alert('タッチされました');
};

 

コメントを残す

あなたのメールアドレスは公開されません。必須項目には印がついています *