Sign in to follow this  
fiverivers

How do I do this?!

Recommended Posts

Create the sprites and add an id to it. Enable input then add a callback to the onInputDown or onInputUp event which passes the sprite that was clicked. You can then access that sprite.

var i, sprite;// creating your 8 sprites with id from  0 to 7for (i = 0; i < 8; i += 1) {  sprite = game.add.sprite(0, 0, 'sprite');  sprite.id = i;    // we need to enable input before we can access the input events  sprite.inputEnabled = true;  // add the callback to the input down event  sprite.events.onInputDown.add(function (clickedSprite) {      console.log('the id of the sprite I clicked = ' + clickedSprite.id);  }, this);}

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.

Guest
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.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.