pixijs / pixi-react

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

Bug: pixi.js v7.2.3 events not working #432

Closed dineug closed 11 months ago

dineug commented 1 year ago

Current Behavior

pixi.js v7.2.3 events not working

Expected Behavior

events must work.

Steps to Reproduce

https://stackblitz.com/edit/vitejs-vite-srtkkk?file=src/main.tsx

Environment

Possible Solution

import { EventSystem } from "@pixi/events";

const App = () => {
  return (
    <Stage
      ...
      onMount={(app) => {
        app.renderer.addSystem(EventSystem, "events2");
      }}
    >
       ...
    </Stage>
  );
};

Additional Information

No response

Zlvsky commented 1 year ago

I've faced the same problem can't use getLocalPosition() function event

ahmafi commented 1 year ago

I'm also getting a deprecated message. I have tested it only on pixi.js 7.2.4 and 7.1.4.

PixiJS Deprecation Warning: renderer.plugins.interaction has been deprecated, use renderer.events
Deprecated since v7.0.0
hevans90 commented 1 year ago

This is a potentially game-breaking issue, can a maintainer chime in?

lunarraid commented 1 year ago

If you're not importing pixi.js to auto-register all the plugins, you'll need to import each system. In this case, add

import '@pixi/events';

to your root file.

Blacktiger commented 11 months ago

I was easily able to duplicate this issue and I don't see any way to fix it. I tried import '@pixi/events, but that obviously does nothing since pixi is already being imported. Here is a code sandbox that shows a minimal reproduction using all the latest pixi and react dependencies: https://codesandbox.io/s/compassionate-microservice-thp345?file=/src/index.tsx

I just wired up a click handler on a div element and a click handler on an @pixi-react Sprite. Only the div click works.

lunarraid commented 11 months ago

@Blacktiger For your case, you're not setting eventMode on the Sprite. Try setting eventMode="static" in the props.

Blacktiger commented 11 months ago

Thanks @lunarraid. For some reason I thought that I didn't need to do that with regular pixi but I guess I must have missed how that worked.