LoginSignup
5
7

More than 5 years have passed since last update.

pixi.js - タッチイベント(マウスイベント)

Last updated at Posted at 2016-07-14

pixi.js - タッチイベント(マウスイベント)

ボタンをクリックすると、アラートが表示されるデモです。
Demoページ(jsfiddle)

index.html
<script src="https://cdnjs.cloudflare.com/ajax/libs/pixi.js/3.0.11/pixi.min.js"></script>
<script src="./script.js"></script>
script.js
var size = {
    w: window.innerWidth, 
  h: window.innerHeight,
};

//レンダラーの生成
var renderer = PIXI.autoDetectRenderer(size.w, size.h, null);
//Canvasをbodyの子要素として追加
document.body.appendChild(renderer.view);

//ステージの生成
var stage = new PIXI.Container();

//ボタンの生成
var button = new PIXI.Text('BUTTON',{font : '50px Arial', fill : 0xffffff, align : 'center'});
button.width = size.w * 0.2;
button.height = size.w * 0.1;
button.anchor.x = 0.5;
button.anchor.y = 0.5;
button.position.x = size.w * 0.5;
button.position.y = size.h * 0.5;
//ボタンをステージに追加
stage.addChild(button);

//タッチイベント(マウスイベント)を有効化
button.interactive = true;
//イベントの追加
button
.on('click', function () {
  alert('button clicked');
})
.on('touchstart', function () {
  alert('button touchstarted');
});

//レンダリング
renderer.render(stage);

リンク

pixi.js公式サイト

以上です。

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