Pixi.js: Graphic element not binding click

Created on 8 May 2019  路  14Comments  路  Source: pixijs/pixi.js

Hi
I can't make a Graphic element to be clickable, here the demo:

https://codepen.io/federicovezzoli/pen/MxMxGo?editors=0010

Tried both with or without hitArea.

Pixi V.4.8.7, cannot make it in 5.0.2 because I don't understand how the legacy works and I'm using context 2d.

thanks!

Most helpful comment

Ok, finally got it. A correct hitArea made it work! thanks!

All 14 comments

Here's the problematic code:

track.click = (e) => { 
      //handle event
      console.log("total track clicked")
}

should be:

track.on('click', (e) => { 
      //handle event
      console.log("total track clicked")
})

There is no click property of DisplayObject/Graphics in PixiJS.

Its legacy that came from v3

@federicovezzoli for the latest docs, go here: http://pixijs.io/docs

Sorry guys, already tried that, not working either:
https://codepen.io/federicovezzoli/pen/MxMxGo?editors=0010

sorry @bigtimebuddy, could you please re-open this? I can't find a way to make a graphic element interactive.
thanks.

Your example works for me @federicovezzoli the click handler works correctly and I see the console log that says total track clicked. Can you be more specific about what's not working?

that's weird @bigtimebuddy, my codepen example still doesn't work for me, I don't understand. (tried both safari and chrome)
Simply the handler doesn't fires.
The example made from @themoonrat works well though.

I can click on the bottom-right hand corner of your demo. So where the white line starts is the top-left corner of the hitArea.

ok, If I disable the hit area no event is fired. Is that because of the way I compose the line?

Lines are ignored for interactivity. If you want to make them interactive, you need to create a polygon hitArea to match the line. For example:

https://jsfiddle.net/bigtimebuddy/xspmq8au/

Ok, finally got it. A correct hitArea made it work! thanks!

Awesome. Closing issue

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Makio64 picture Makio64  路  3Comments

finscn picture finscn  路  3Comments

YuryKuvetski picture YuryKuvetski  路  3Comments

Darker picture Darker  路  3Comments

courtneyvigo picture courtneyvigo  路  3Comments