fiverivers Posted June 29, 2014 Share Posted June 29, 2014 Hi there, I want to make 8 sprites and assign an ID to each one and then whenever I click on a sprite I would like the ID to be returned so that I can check which one was clicked. Kind regards, Link to comment Share on other sites More sharing options...
phaserdragoon Posted June 29, 2014 Share Posted June 29, 2014 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);} mtburdon 1 Link to comment Share on other sites More sharing options...
Recommended Posts