GithubHelp home page GithubHelp logo

novout / pixi-controller Goto Github PK

View Code? Open in Web Editor NEW
6.0 3.0 0.0 752 KB

:ballot_box_with_check: Event Manager for Pixi.js

Home Page: https://novout.github.io/pixi-controller

License: MIT License

JavaScript 0.95% TypeScript 99.05%
pixijs pixi-js package

pixi-controller's Introduction

PIXI.JS Controller

License Badge Version Badge Bundle Badge

Set of controls for Pixi.js to facilitate general handling of external events.

Install

npm install pixi.js pixi-controller

or

yarn add pixi.js pixi-controller

Simple 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

pixi-controller's People

Contributors

novout avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

pixi-controller's Issues

Feel free to contribute upstream

I'm the creator of the mouse/keyboard plugin, feel free to contribute now that I've got public github pages.

Also, you spelt my credit wrong. It's -nom- not -non-. But it's okay. :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.