Hi
i am trying to create a function that, when i touch on this object i will do some code, something like:
1 2 3 4 5 | local select = function() if (my block is selected by touch on this block) then ------>("need to know how to do it") i will write some code elseif (my block is deselected by touch on another object or on the background) ------>("need to know how to do it") i will write some code |
local obj1 = display.newRect(100,100, 10,10)
local obj2 = display.newRect(200,200, 10,10)
local function func(event)
if event.pahse=="ended" then
if event.target==obj1 then
-- some code for object 1
elseif event.target==obj2 then
-- some code for object 2
end
end
end
obj1:addEventListener("touch", func)
obj2:addEventListener("touch", func)
Thanks aabweber, only one more doubt, i do:
if event.target==obj1 then
--some code
and what i need to use to do that:
when i touch on the background...some code, now not on objects on other think, now is on the background, if i touch on background i need to do some code but i cant make equal than objects.
to objects i use
if event.target==obj1 then
to background how i can make?
put an object on the background (like, an image...?) and, in another elseif statement, check for it's handler
1 2 3 | elseif event.target== backGroundImage then -- some code for bg end |
i tryed it before and didnt work, but now i try it again and works perfectly
Thanks for all the help developers :)