Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: pointer events not working on Graphics without a sprite #402

Open
waspeer opened this issue Feb 8, 2023 · 8 comments
Open

Bug: pointer events not working on Graphics without a sprite #402

waspeer opened this issue Feb 8, 2023 · 8 comments
Assignees

Comments

@waspeer
Copy link

waspeer commented Feb 8, 2023

Current Behavior

Creating a simple Stage with one or more interactive Graphics with a pointer event handler will not actually make the Graphics interactive. Only when at least one Sprite is present on the Stage, all interactive elements work as expected.

Expected Behavior

I expect interactive elements to be interactive without being dependent on other elements that are on the Stage.

Steps to Reproduce

Reproduction: https://codesandbox.io/p/sandbox/mystifying-shockley-4kcn68

Environment

Possible Solution

No response

Additional Information

No response

@joonhocho
Copy link

same issue. adding sprite to the stage fixes the issue.

@fergusmeiklejohn
Copy link

I'm got a similar issue. Sprite will cease to be interactive sometimes. Like if I reload vscode all Sprite interactions cease (seriously.. that's the observed behaviour). For some totally weird reason adding a useState and array of clicks and rendering them in a list brings the interactivity back. I have no idea how to begin to debug this. But there is definitely a bug somewhere in the click handler

@fergusmeiklejohn
Copy link

I've got a reproduction and a new issue here: #416
Seems likely that these bugs are related..

@wkf
Copy link

wkf commented Mar 13, 2023

Hey there, I believe I've experienced this same issue. Including a texture-backed Sprite in the Scene does "fix" interactions, but so does just (for instance) printing Texture.WHITE to the console, without rendering any additional Sprite. Also, if you try to include an image-backed Sprite, interactions are still broken. To me, this implies that something is being initialized when the Pixi library is used for the first time.

@TimKraemer
Copy link

might be related to import { Texture } from "pixi.js" - I noticed, when adding this line to the "without" example it works

@jasonmcleod
Copy link

jasonmcleod commented Jul 13, 2023

I ran into this interactive graphics issue and after some trial and error I've found another workaround. For whatever reason, this call to BlurFilter is somehow making the events work again.

import { BlurFilter } from "pixi.js";

export default function InteractiveBug() {
  // without this line, all mouse events are broken
  useMemo(() => new BlurFilter(0), []);

  return (
    <Stage>
      <Container width={200} height={200}>
        <Graphics
          interactive={true}
          onmousemove={() => {
            console.log("onmousemove called");
          }}
          x={100}
          y={100}
          width={100}
          height={100}
          draw={(g) => {
            g.clear();
            g.lineStyle(4, 0x000000);
            g.beginFill(0xff0000);
            g.drawRect(0, 0, 100, 100);
            g.endFill();
          }}
        />
      </Container>
    </Stage>
  );
}

@scottanglr
Copy link

scottanglr commented Oct 11, 2023

I wasn't able to make the Graphics element interactive with any of the above methods. After adding all three of these props I can now click Graphics. Note the required hitArea prop.

<Graphics
    eventMode={"static"}
    hitArea={new Rectangle(0, 0, props.width, props.height)}
    onclick={() => {
        console.log("ON CLICKING!!");
    }}
/>

@jpraccio0722
Copy link

Can confirm I have the same issue as @fergusmeiklejohn
adding:

<Sprite texture={Texture.WHITE} width={1} height={1}/>

fixes the issue for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants