Jump to content

How do I do this?!


fiverivers
 Share

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);}
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...