renathy 0 Report post Posted November 24, 2020 What is the best way to emit events from one sprite and listen them on another sprite or container? 1) I have toolbar with buttons like "delete, resize etc.' . When user clicks on sprites on the screen (a lot of them), I need to emit "Sprite is clicked" and save "Sprite" into event's data. So, toolbar will listen to the event and will know which sprite to be "delete, resize etc.". 2) Second scenario is when user clicks on custom sprite (Background: PIXI.Sprite), I need to change background of another Sprite. I have multiple Background sprites. In this case "Background" click should Emit event. And Sprite will listen and change its background. Quote Share this post Link to post Share on other sites
jonforum 90 Report post Posted November 28, 2020 (edited) you can use Observe https://www.npmjs.com/package/observe/v/1.2.0 or this one is better, i using it with React, because everything is immutable (@read-only).https://www.npmjs.com/package/@nx-js/observer-util Or in vanilla, but why reinvent the wheel?https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent Actualy PIXI natively give you event for listen child's change, but not for props, or is missing in the doc. ! A PIXI guys can maybe fix me if am wrong. Note: Do not confused with the obsolete native version in Js vanilla, it was removedhttps://developer.mozilla.org/en-US/docs/Archive/Web/JavaScript/Object.observe "You can use the more general Proxy object instead." is what @nx-js/observer-util dohttps://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy Edited November 28, 2020 by jonforum Quote Share this post Link to post Share on other sites