Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Touch event on single rather than multiple objects
Started by ondra.vaic Oct 16 2015 10:48 AM

- - - - -
1 reply to this topic
touch event addeventlistener

Best Answer bjsorrentino , 16 October 2015 - 01:35 PM

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.

 

local function KruhListener(event)
    if event.phase == "began" then
        display.remove(event.target)
    end
    return true  -- Add this
end

 

Best regards,,

Brent

[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

ondra.vaic

[GLOBAL: userInfoPane.html]
ondra.vaic
  • Observer

  • 6 posts
  • Corona SDK

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. 

 

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()



[TOPIC: post.html]
#2

bjsorrentino

[GLOBAL: userInfoPane.html]
bjsorrentino
  • Veteran

  • 8,506 posts
  • Corona SDK

  Best Answer

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.

 

local function KruhListener(event)
    if event.phase == "began" then
        display.remove(event.target)
    end
    return true  -- Add this
end

 

Best regards,,

Brent




[topic_controls]
 
[/topic_controls]