pixijs / pixi-react

Write PIXI apps using React declarative style
https://pixijs.io/pixi-react/
MIT License
2.33k stars 177 forks source link

Can't install @pixi/events plugin #333

Closed sabigara closed 2 years ago

sabigara commented 2 years ago

Description

First of all, thank you for creating this awesome library! It's been helping me a lot.

I'm trying to use @pixi/events plugin (doc) with react-pixi but experiencing trouble.

We need to delete the default interaction plugin before installing @pixi/events:

import { Renderer, Loader } from "pixi.js";

delete Renderer.__plugins.interaction;

const app = new PIXI.Application();
const { renderer } = app;

renderer.addSystem(EventSystem, 'events');

But react-pixi is trying to set the resolution of interaction at: https://github.com/inlet/react-pixi/blob/11e258e05f57a7609831125bb89b226bc685ccc6/src/stage/index.js#L211-L213

So an error is thrown.

It seems react-pixi only refers to plugins.interaction here so a simple existance check may be enough:

resetInteractionManager() {
  if("interaction" in this.app.renderer.plugins) {
      this.app.renderer.plugins.interaction.resolution = this.app.renderer.resolution
  }
}

If this solution is OK, I would make a PR.

Steps to reproduce

https://codesandbox.io/s/thirsty-cloud-cd17s3?file=/src/App.js

Additional info

inlet commented 2 years ago

Sounds like a good solution, yes please create a PR. Thanks!

inlet commented 2 years ago

Fixed in #335