ptotheaul Posted September 28, 2016 Share Posted September 28, 2016 I'm creating a group that has a few different image sprites and animations in that group. I use one sprite in the group for the click sprite. What I need to know is how to target the other sprites in the group from the click function. ie: in the below code in 'itemClick' i'd like to set s1 invisible and set s2 visible item_ctor: function() { var item_g = this.game.add.group(); var s1= imageLoader.sprite(0, 0, 'Idle.png'); var s2= imageLoader.sprite(0, 0, 'state1.png'); s2.visible = false; var over= imageLoader.sprite(0, 0, 'hamster/Bubbles/over.png'); item_g.add(s1); item_g.add(s2); item_g.add(over); s1.inputEnabled=true; s1.events.onInputDown.add(this.itemClick,this); }, itemClick: function (sprite, pointer) { console.log("click"); sprite.visible = false; -> THIS WORKS HOW WOULD I TARGET s2 FROM HERE? }, Link to comment Share on other sites More sharing options...
lumoludo Posted September 29, 2016 Share Posted September 29, 2016 Sprites have a .parent property that you can use. Something like this: sprite.parent.children[1].visible = false; Not the prettiest code, but it should work. Link to comment Share on other sites More sharing options...
Recommended Posts