Jump to content

Targeting other item in same group when sprite is clicked


ptotheaul
 Share

Recommended Posts

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

 Share

  • Recently Browsing   0 members

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