Ok, I found another way.
You can assign any field to your sprite.
So say you have a sprite called HERO, assign it a field called anything you like - say, ID.
You set ID as usual…
Hero.ID = “MyHero”
Then in your event handler code, you do this little trick…
[code]if event.target.ID == “MyHero” then
…you’ve got the right sprite!!![/code]
The event.target passes back the object which the event occurred on, and from that you can get any properties that you set on that object. Clever!
The documentation states:
event.target
“The display image object associated with the touch event. This value will be nil if this was called by a Runtime Touch event.”
Being a noob, I did not realise that a sprite is just another display image object. And I did not appreciate that you can attach your own fields to any object, because of the freedom provided by LUA.
Using this, you can have just one function that handles an event, and assign that one function to all your sprites - making sure that each sprite has a unique ID or name or whatever. Then you just check the ID and act accordingly.
Hope this helps.
JB
[import]uid: 58328 topic_id: 13381 reply_id: 49204[/import]