Problem with touch in Corona on multiple views solved.

By | January 19, 2012

Hello everyone..
There has been a problem with corona that when you place one view over the other and when you touch the object in front of the other, touch will be migrated to the object below it. To prevent this there is a mechanism in corona.
Here is how we solve this in corona.

display.getCurrentStage():setFocus( your_touched_obj)

here is a sample code.


local img1 = display.newImage("android_1.png")
local img2 = display.newImage("android_2.png")

function touchedImageOne()
	print ("touched Image One")
end

function touchedImageTwo()
	print ("touched Image two")
end

display.getCurrentStage():setFocus( img2 )
img1:addEventListener("tap",touchedImageOne);
img2:addEventListener("tap",touchedImageTwo);

Check the console for the output
Here is a source code example for this project.

Leave a Reply

Your email address will not be published. Required fields are marked *