Set of controls for Pixi.js to facilitate general handling of external events.
- pixi-controller is based on pixi.js-mouse and pixi.js-keyboard
- Documentation is here
npm install pixi.js pixi-controller
or
yarn add pixi.js pixi-controller
import * as PIXI from 'pixi.js';
import { PIXIController, BUTTON, PLAYER } from 'pixi-controller';
const app = new PIXI.Application();
document.body.appendChild(app.view);
app.loader.add('example', 'example.jpg').load((loader, resources) => {
const Controller = new PIXIController();
const example = new PIXI.Sprite(resources.example.texture);
app.stage.addChild(example);
Controller.Mouse.prevent(BUTTON.RIGHT);
app.ticker.add(() => {
if(Controller.Mouse.isButtonDown(BUTTON.LEFT)) {
console.log('left')
}
if(Controller.Mouse.isButtonDown(BUTTON.RIGHT)) {
console.log('right')
}
if (Controller.Keyboard.isKeyDown(...PLAYER.LEFT))
example.x -= 1;
if (Controller.Keyboard.isKeyDown(...PLAYER.RIGHT))
example.x += 1;
if (Controller.Keyboard.isKeyDown(...PLAYER.UP))
example.y -= 1;
if (Controller.Keyboard.isKeyDown(...PLAYER.DOWN))
example.y += 1;
Controller.update();
});
});
-nom- for creation pixi.js-mouse and pixi.js-keyboard