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

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

  • Recently Browsing   0 members

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