Touch Event Hides Multiple Objects

I have three objects that I want to hide upon touch. Every time I touch one object the other two are hidden as well. I want to be able to touch each object and hide that specific object. Here is my code so far:

display.setStatusBar (display.HiddenStatusBar)

local background = display.newImage (“background.png”)
local circle = display.newImage(“circle.png”)
circle.x = 170 circle.y = 230
local square = display.newImage(“square.png”)
square.x = 120 square.y = 330
local triangle = display.newImage(“triangle.png”)
triangle.x = 230 triangle.y = 392

local function hidecircle (event)
circle.isVisible = false
end

local function hidesquare (event)
square.isVisible = false
end

local function hidetriangle (event)
triangle.isVisible = false
end

circle:addEventListener (“touch” , hidecircle)
square:addEventListener (“touch” , hidesquare)
triangle:addEventListener (“touch” , hidetriangle) [import]uid: 3318 topic_id: 10871 reply_id: 310871[/import]

Hey there,

How big are your images? Are they overlapping at all? If you are touching more than one at once, then more than one will respond.

Peach :slight_smile: [import]uid: 52491 topic_id: 10871 reply_id: 39776[/import]

Add “return true” to the end of each touch handler function. This will mark the event as handled and it won’t propagate any further. [import]uid: 5833 topic_id: 10871 reply_id: 39782[/import]

Peach,tanks for pointing that out. I’m embarrassed to admit that was the issue. I thought for sure I had just saved the shape, but each shape was saved as the full 960x640.

Thanks for your reply too Graham. [import]uid: 3318 topic_id: 10871 reply_id: 39898[/import]

No worries; and indeed, Graham is quite the clever fellow :slight_smile:

Glad you got it worked out :slight_smile: [import]uid: 52491 topic_id: 10871 reply_id: 39941[/import]