AdamRyanGameDev

setInteractive() on a whole group

Recommended Posts

I would like to make a group interactive.

The following did not work

groupOfZombies.setInteractive();

Then just to add the resulting code to discover which sprite was clicked needs to me access the sprite-key, i have been looking for it but I can't seem to find it (mainly because most code functions using 'this')

spriteCat2.setInteractive();
spriteCat2.on('pointerdown', function () {
			
   var thisSpriteName = this.key;
	console.log(thisSpriteName);

});

any help would be appreciated!

 

Share this post


Link to post
Share on other sites

You could do:

this.input.setHitArea(group.getChildren());

To figure out which sprite was clicked there are several ways of doing it. Either the 'gameobjectdown' events, or listen on the sprite itself. There's a tutorial about exactly this here: https://madmimi.com/p/a022cb

Share this post


Link to post
Share on other sites

Just to elaborate on Rich's answer since it wasn't abundantly clear to me because I'm a noob and I had to fiddle with it a bit...

 

this.input.setHitArea(groupName.getChildren()).on('gameobjectdown', function(pointer, gameObject) {

        
        
});

 

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.