jilonor Posted November 25, 2015 Share Posted November 25, 2015 Hello, i was trying to attach eventListeners to sprites. I did that in the create function :this.selectorGroup = game.add.group();height = 200;// looping through json for(var key in res){ var selector = game.add.sprite(625, height - 10, "resourceSelector"); selector.inputEnabled = true; // adding some custom property selector.data = key; // attaching eventListener selector.events.onInputUp.add(this.triggerSearch); // adding the sprite to a group this.selectorGroup.add(selector); height = height+40;}// setting all elems of the group to alpha 0this.selectorGroup.alpha = 0;then in the callback function :triggerSearch = function (item, pointer) { // this is working console.log("looking for ", item.data); // hide previous selections this.selectorGroup.alpha = 0; // this isnt working item.alpha = 1;};also, i cant access the selectorGroup to apply alpha 0 to all children in order to reset previous selections. though, if i dont set alpha to 0 to sprites in create function and i put item.alpha = 0 in the callback, i can remove opacity from the sprites... Am i missing something? Link to comment Share on other sites More sharing options...
jmp909 Posted November 26, 2015 Share Posted November 26, 2015 Thats wrongthis.selectorGroup.alpha = 0; that would just set the group alpha to 0, not the children's alpha either use setAll or forEach jilonor 1 Link to comment Share on other sites More sharing options...
jilonor Posted November 26, 2015 Author Share Posted November 26, 2015 thanks a lot for the answer. So this fixes the initialization but i would also want to reset all previous selection when entering the callback. And I can't manage to access the group (this.selectorGroup). Doesnt seems to be initialized in this context. Link to comment Share on other sites More sharing options...
jmp909 Posted November 26, 2015 Share Posted November 26, 2015 Probably wrong context for "this". Put ,this) At the end of your .addhttp://phaser.io/docs/2.4.4/Phaser.Signal.html#add Link to comment Share on other sites More sharing options...
jilonor Posted November 26, 2015 Author Share Posted November 26, 2015 working perfectly thx Link to comment Share on other sites More sharing options...
Recommended Posts