touch event on different object on same screen

Hello Friends

I am developing a game in which i have 20 images on one screen, now the logic is such when a player touch one specific object it shows you won and if he touch others than it shows you lost.

So can any one guide me how shall i proceed?

Regards
Varun [import]uid: 130269 topic_id: 26062 reply_id: 326062[/import]

You could spawn the 19 “bad” images in a loop and assign the listener to them that way, it would be quicker than manually.

:slight_smile: [import]uid: 52491 topic_id: 26062 reply_id: 105565[/import]

[lua]local numObjects = 20
local theObjects = {}
local function theTouch(self,event)
if event.phase == “ended” and self.target == true then
– some good result
elseif event.phase == “ended” then
– some bad result
end
return true
end

for i=1,numObjects do
theObjects[i] = display.newImage(“some_image.png”)
–theObjects[i].x, theObjects[i].y = some x, some y
theObjects[i].target = false
theObjects[i]:addEventListener(“touch”, theTouch)
end

theObjects[math.random(numObjects)].target = true[/lua] [import]uid: 44647 topic_id: 26062 reply_id: 105596[/import]