umair-khan Posted July 20, 2015 Share Posted July 20, 2015 So I have a group, and it has three sprites. create() { var parent = game.add.group(); var allSprites = [ 'sprite1', 'sprite2', 'sprite3']; for (i=0; i<3; i++){ childImage = parent.create( game.world.centerX, game.world.centerY+ (i*30), allSprites); childImage.anchor.setTo(0.5, 1); childImage.inputEnabled = true; childImage.input.useHandCursor = true; }} How to I trigger function changeText(); when one of the child sprite is clicked.So far I have tried this method below but it only detects click on the last sprite.update(){ child.events.onInputDown.add(changeText, this);} Link to comment Share on other sites More sharing options...
rich Posted July 21, 2015 Share Posted July 21, 2015 for (var i = 0; i < 3; i++) { childImage = parent.create( game.world.centerX, game.world.centerY+ (i*30), allSprites[i]); childImage.anchor.setTo(0.5, 1); childImage.inputEnabled = true; childImage.input.useHandCursor = true; childImage.events.onInputDown.add(yourClickFunction, this); } ... function yourClickFunction(sprite, pointer) { sprite.alpha = 0.5; } Link to comment Share on other sites More sharing options...
DudeshootMankill Posted October 31, 2016 Share Posted October 31, 2016 Sorry for raising a dead horse from the grave here, but i'm having major troubles with this solution when using a gamestates. function yourClickFunction(sprite, pointer) { sprite.alpha = 0.5; } i would have to use this. here (this.sprite, this.pointer) . But that throws up an error. Thank you for your time. Link to comment Share on other sites More sharing options...
DudeshootMankill Posted October 31, 2016 Share Posted October 31, 2016 Disregard this please, it was a brain fart on my end. Link to comment Share on other sites More sharing options...
Recommended Posts