pixijs / pixi-react

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

Bug: click handlers not working on sprites #416

Open fergusmeiklejohn opened 1 year ago

fergusmeiklejohn commented 1 year ago

Current Behavior

I've found a bug with the Sprite click handlers. See repo and 20sec video for clear explanation.. Basically if a Sprite Texture is in the stage, and the page is refreshed, the click handlers on the image Sprite will work, comment out the Texture and refresh and the click handlers stop working.

Expected Behavior

Click handlers should always work

Steps to Reproduce

https://stackblitz.com/edit/vitejs-vite-21bwq5?file=src%2FApp.tsx

https://user-images.githubusercontent.com/11864025/219828228-283538dd-11ab-476d-bc7a-d212dd884504.mp4

Environment

    "@pixi/react": "^7.0.2",
    "pixi.js": "^7.1.2",
    "react": "^18.2.0",
    "react-dom": "^18.2.0"

Possible Solution

No response

Additional Information

No response

fergusmeiklejohn commented 1 year ago

Seems related to this issue: https://github.com/pixijs/pixi-react/issues/402

SergeyAlexeev commented 1 year ago

Hi! Are there any updates?)

lostfictions commented 11 months ago

Click events are also not working for me. I guess pixi-react is just like... aspirational? Like it's not really a thing that is ready for general usage?

hreinn91 commented 6 months ago

Hey I think you need to import pixi events to get it to work. Add this as a import, it's enough to add it in the same file as where you define the Stage it will propagate.

import '@pixi/events';

This is mentioned in the FAQ of the pixi-react 'About' page: https://pixijs.io/pixi-react/

I tried adding the import in your stackblitz example and that did indeed resolve this problem.