renathy Posted November 24, 2020 Share 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 Link to comment Share on other sites More sharing options...
jonforum Posted November 28, 2020 Share 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 Link to comment Share on other sites More sharing options...
flatliner Posted February 2, 2021 Share Posted February 2, 2021 (edited) EventEmitter can not help on this? PS: I am just trying to implement something like topic starter was. So, I am searching for understandable solution for me. I am not expert in pixi... and in javascript too. I would be nice to show me a small example, how I can do this Edited February 2, 2021 by flatliner add small postscriptum Quote Link to comment Share on other sites More sharing options...
flatliner Posted February 3, 2021 Share Posted February 3, 2021 (edited) Eventually, I need only one solution (if it possible). Using EventEmitter can we use some one object (like stage or canvas) to emit our event to it, and it will propagate this event to all its child objects? Or we need keep array of all objects to emit events for each of them one by one? Edited February 3, 2021 by flatliner Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.