Sign in to follow this  

Unique ID of Sprite, Button etc.

Recommended Posts

Hi Guys,


I have a question of obtaining some form of a unique ID from a sprite / button, let me explain.


I have a main menu which loads a random number of items which are clickable (at the moment they are buttons, which I'm not sure is correct or if they should be sprites). I also have a JS object which represents each of these created items (the objects are put into an array).


At the moment when the Phaser button is created (in a for loop), I attach the button to the JS object when it is created, so that it is stored. As a callback function on the clickable button, I try and pass the unique ID of the object so that I can quickly access which ever object is attached to that particular button and get all the details.


However, when I alert the unique ID on button click, it keeps displaying the same one, regardless of the button I click. Now I know this must be wrong and I presume I should be attaching the custom object to the button instead, but I'm not too sure how to do that. If that is also incorrect, what steps should I take to link my object to a clickable button/sprite?


The idea is that once a button is clicked, a small menu dialog appears with the details etc. depending on the item clicked


Many Thanks!

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.