Sign in to follow this  

event emiter/listener

Recommended Posts

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.

Share this post

Link to post
Share on other sites

you can use Observe
or this one is better, i using it with React, because everything is immutable (@read-only).


Or in vanilla, but why reinvent the wheel?


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.


Do not confused with the obsolete native version in Js vanilla, it was removed
"You can use the more general Proxy object instead." is what @nx-js/observer-util do

Edited by jonforum

Share this post

Link to post
Share on other sites

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.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.