Touch event on single rather than multiple objects

Hello,

I ran into a problem while making a game. I made a generator of circles that fire to random locations. Player will touch the circle to remove it and the goal is to get rid of them all.

The problem is that if two circles overlap they both get removed.

Can anyone help me please? I’m sure there must be some really easy solution but I starting to get kinda desperate. 

[lua]local function Shoot()

local random = math.random(0,display.contentWidth)

local kruh = display.newImage(“kolecko.png”,display.contentCenterX ,100)

local function KruhListener(event)

if event.phase == “began” then

display.remove(event.target)

end

end

kruh:addEventListener( “touch”, KruhListener )

local transition = transition.to(kruh, {x = random,y = display.contentHeight, time = 4500})

end

local function GameStart()

for i=1, 10 do

Shoot()

end

end

GameStart()[/lua]

Hi @ondra.vaic,

This is a common question, and it’s easily solved. Just add “return true” as the last line within the touch listener ("KruhListener "). This will prevent the touch from propogating to objects behind the one that was initially touched.

[lua]

local function KruhListener(event)

    if event.phase == “began” then

        display.remove(event.target)

    end

    return true  – Add this

end

[/lua]

Best regards,

Brent

Hi @ondra.vaic,

This is a common question, and it’s easily solved. Just add “return true” as the last line within the touch listener ("KruhListener "). This will prevent the touch from propogating to objects behind the one that was initially touched.

[lua]

local function KruhListener(event)

    if event.phase == “began” then

        display.remove(event.target)

    end

    return true  – Add this

end

[/lua]

Best regards,

Brent