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);
リンク
以上です。