Shapeの原点を変更する【Phina.js】

Shapeの原点を変更する

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

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

  // 継承
  superClass: 'DisplayScene',

  //初期化
  init: function () {
    //親クラス初期化
    this.superInit();
    //背景色
    this.backgroundColor = 'lightgray';
    //shapeを作成してシーンに追加
    var shape = Shape().addChildTo(this);
    //移動
    shape.x = 320;
    shape.y = 480;
    //回転
    shape.update = function () {
      shape.rotation += 2;
    };

    var shape2 = Shape().addChildTo(this);
    //移動
    shape2.x = 320;
    shape2.y = 240;
    //左上を原点に
    shape2.origin.set(0, 0);
    //回転
    shape2.update = function () {
      shape2.rotation += -2;
    };

    var shape3 = Shape().addChildTo(this);
    //移動
    shape3.x = 320;
    shape3.y = 720;
    //右下を原点に
    shape3.origin.set(1, 1);
    //回転
    shape3.update = function () {
      shape3.rotation += -2;
    };
  },
});

//メイン処理

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

 

▷originプロパティと原点の位置

オブジェクトの原点はoriginで指定ができる。

origin.set(0.5, 0.5)・・・中心(デフォルト)
origin.set(0, 0)・・・左上
origin.set(0, 1)・・左下
origin.set(1, 0)・・右上
origin.set(1, 1)・・右下

コメントを残す

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