Package Exports
- pixi-controller
- pixi-controller/dist/index.js
- pixi-controller/dist/index.mjs
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (pixi-controller) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
PIXI.JS Controller
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
Install
npm install pixi.js pixi-controller
or
yarn add pixi.js pixi-controllerSimple Example
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();
});
});Credits
-nom- for creation pixi.js-mouse and pixi.js-keyboard