pixi-components

A pixi.js plugin that adds methods for a component-based architecture in pixi.

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
pixi-components
201.7.09 months ago10 months agoMinified + gzip package size for pixi-components in KB

Readme

pixi-components
Project check codecov npm version
A pixi.js plugin that adds methods for a component-based architecture in pixi. It has a very similar API like Unity's GameObject and MonoBehaviour.
The motivation behind this approach is to create single-responsibility components that are easier to reuse, test and debug. On top of that, it enables development experience features like hot module replacement (with limitations).

Getting started

npm install pixi-components

The plugin needs to be installed manually and bound to the application ticker:
import { installPlugin } from 'pixi-components';

installPlugin();
registerUpdateTicker(app.ticker, app.stage);

Example

class RotateComponent extends Component {
  speed: number;

  constructor(speed: number) {
    super();

    this.speed = speed;
  }

  public update(deltaTime: number): void {
    if (!this.gameObject) {
      return;
    }

    this.gameObject.rotation += this.speed * deltaTime;
  }
}

installPlugin();
registerUpdateTicker(app.ticker, app.stage);

const texture = Texture.from('/demos/assets/bunny.png');
const bunny = new Sprite(texture);

const rotateComponent = new RotateComponent(0.05);
bunny.addComponent(rotateComponent);

Development

  1. Clone the repository
  2. Install the dependencies with npm ci
  3. Run the development server with npm run dev

Alternatively, run the tests in watch mode with npm run test -- --watch

License

MIT