Kobaltic Posted February 11, 2014 Share Posted February 11, 2014 I want to click on a sprite and return the index from that sprite. Is there a way I can do that? Link to comment Share on other sites More sharing options...
XekeDeath Posted February 11, 2014 Share Posted February 11, 2014 Which index are you referring to?Is it in a group?Or did you assign the sprite an index like 'sprite.index = value'? Either way, the sprite is the first argument passed to the callback function assigned to the click.//Create a spritevar sprite = game.add.sprite(...);//Give it an indexsprite.index = 0;//Enable inputsprite.inputEnabled = true;//Add callbacksprite.events.onInputDown.add(clickCallback, this);//Put it in a groupgroup.add(sprite);clickCallback = function(sprite){ console.log(sprite.index); console.log(group.getIndex(sprite));} Link to comment Share on other sites More sharing options...
rich Posted February 11, 2014 Share Posted February 11, 2014 In 1.1.4:sprite.group.getIndex(sprite);Could be done in a callback as Xeke said. jerome 1 Link to comment Share on other sites More sharing options...
Kobaltic Posted February 11, 2014 Author Share Posted February 11, 2014 Thanks for the quick responses. It turns out that I really wanted to pass the sprite as an argument into the call back. I didn't think that was possible but since it is I just passed the sprite through and it now works as expected. Link to comment Share on other sites More sharing options...
Recommended Posts