one object touch

Hi all,

My code is below:

[lua]aa={}

local function onTouch(event)
if event.phase == “began” then
print(event.target.name)
end
end

aa[1] = display.newRoundedRect( 20, 20, 50, 50, 4)
aa[1].name = “a1”
aa[1]:setFillColor(255, 0, 0)
aa[1]:addEventListener( “touch”, onTouch )

aa[2] = display.newRoundedRect( 20, 40, 50, 50, 4)
aa[2].name = “a2”
aa[2]:setFillColor(0, 255, 0)
aa[2]:addEventListener( “touch”, onTouch )

[/lua]

When i click green box on top side, I have opted for both the red and green box but i want opted only front box. 

how can i do this?? :huh:

Thank you in advance :)  

i don’t quiet understand your question.  can you please specify

try this out, hope it helps :slight_smile:

  1. aa={}
  2. local function onTouch(event)
  3. if event.phase == “began” then
  4. print(event.target.name)
  5. end
  6. return true
  7. end
  8. aa[1] = display.newRoundedRect( 20, 20, 50, 50, 4)
  9. aa[1].name = “a1”
  10. aa[1]:setFillColor(255, 0, 0)
  11. aa[1]:addEventListener( “touch”, onTouch )
  12. aa[2] = display.newRoundedRect( 20, 40, 50, 50, 4)
  13. aa[2].name = “a2”
  14. aa[2]:setFillColor(0, 255, 0)
  15. aa[2]:addEventListener( “touch”, onTouch )

hİ harryjnewton,

difference is return true and it is working properly :slight_smile:

How is it working now??

Thank you for help

well that’s a great question, lets say for example that there is a draggable fly in you game, and there is a lily pad in the game also for a frog to hop on to when you tap on it, and lets say the fly and frog are both in the same position as each other, and you only want to select the fly to drag around instead of the frog, well you just use return true in your function, which basically says, ok you two display object, im only going to select one of you at a time if you are both in the smae position as each other, or overlapping . do you understand. if you don’t, don’t worry it took me a while to get around as well :slight_smile: hope that helps

I’m guessing that I understand  :slight_smile:

thank you very much again for this fine point 

no worries mate

i don’t quiet understand your question.  can you please specify

try this out, hope it helps :slight_smile:

  1. aa={}
  2. local function onTouch(event)
  3. if event.phase == “began” then
  4. print(event.target.name)
  5. end
  6. return true
  7. end
  8. aa[1] = display.newRoundedRect( 20, 20, 50, 50, 4)
  9. aa[1].name = “a1”
  10. aa[1]:setFillColor(255, 0, 0)
  11. aa[1]:addEventListener( “touch”, onTouch )
  12. aa[2] = display.newRoundedRect( 20, 40, 50, 50, 4)
  13. aa[2].name = “a2”
  14. aa[2]:setFillColor(0, 255, 0)
  15. aa[2]:addEventListener( “touch”, onTouch )

hİ harryjnewton,

difference is return true and it is working properly :slight_smile:

How is it working now??

Thank you for help

well that’s a great question, lets say for example that there is a draggable fly in you game, and there is a lily pad in the game also for a frog to hop on to when you tap on it, and lets say the fly and frog are both in the same position as each other, and you only want to select the fly to drag around instead of the frog, well you just use return true in your function, which basically says, ok you two display object, im only going to select one of you at a time if you are both in the smae position as each other, or overlapping . do you understand. if you don’t, don’t worry it took me a while to get around as well :slight_smile: hope that helps

I’m guessing that I understand  :slight_smile:

thank you very much again for this fine point 

no worries mate