Jump to content

event listeners on sprites with limited context


Recommended Posts



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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

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