event.target doesn't say which child in a displayGroup?

Hi there,

Is there a way for a touch event to say which child in a displayGroup has been clicked? When I try this the event.target returns a table (which I assume is the displayGroup) but I need to know which tile inside the displayGroup is touched - it would be a shame to have to attach a separate touch eventhandler to each child to do this.

Any ideas?

Thanks,
Thomas [import]uid: 70134 topic_id: 23244 reply_id: 323244[/import]

What I do is give each child a name and then get that name in the event.

object.name = “MyName”

Then in the event -

local t = event.target

print t.name

Would print MyName

Dave [import]uid: 117617 topic_id: 23244 reply_id: 93514[/import]

@ thedavebaxter:

Am I correct in assuming that you then need to add the same EventListener to each element in the displayGroup, instead of just once to the whole displayGroup?

I tried what you suggested and added the eventListener to the whole group, but event.target still returned a table, and consequently event.target.name returned nil.

It seems like a lot of overhead to need to add an EventListener to all of the tiles in my displayGroup. [import]uid: 70134 topic_id: 23244 reply_id: 96282[/import]

I use it for a drag and drop type listener, when I add each tile to the group, I add the same event listener to each tile.

Then in the event listener I have a if statement checking the name field, if there is something I need to do for that particular tile.

Dave [import]uid: 117617 topic_id: 23244 reply_id: 96283[/import]

Okay, I’ve got it, thanks for the replies - I love how helpful the forum is here!

I wonder what the overhead is for loads of eventListeners. It’s either using that technique or complicated math :slight_smile:

Thomas

p.s. I’m working on a tile-based game with in-app level editor. Cool stuff but a bit more work than I bargained for! [import]uid: 70134 topic_id: 23244 reply_id: 96291[/import]