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!
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.
At it's most basic level: https://www.pixiplayground.com/#/edit/SG1m3ZN4F8J8LEdI3eqaC
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:
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.
Most helpful comment
Ok, finally got it. A correct hitArea made it work! thanks!