Hello.
I have an image and I want to be untappable after tap the image once.
What way do you suggest to implement it?
The simplest way is to probably include a property in the object that prevents future touch events, for instance:
local function touchEvent( event )
if event.phase == "ended" then
if not event.target.isTouched then
event.target.isTouched = true
-- do stuff
end
end
return true
end
1 Like
You can also removEventListener from the object to eliminate the event completely, but this can sometimes be a bit tricky specially if there are touch events, or physics so it’s better to use a property like XeduR said then remove the event listener when it is appropriate
local arefehObject
local function arefehObject_Tap(event)
print(1)
arefehObject:removeEventListener("tap",arefehObject_Tap)
end
arefehObject = display.newCircle(display.contentCenterX,display.contentCenterY,150)
arefehObject:setFillColor(1,0,0)
arefehObject:addEventListener("tap",arefehObject_Tap)
1 Like
Thank you for your help. This idea taught me a good point.
Thank you for your help. Since there is no touch event and physics , this snippet of code came in handy for me. Thanks again!
nothing makes me happier than helping Arefeh
1 Like