Jump to content

event listeners on sprites with limited context


jilonor
 Share

Recommended Posts

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

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...