jilonor

event listeners on sprites with limited context

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?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
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.

Guest
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.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.