How to disable touch if object is in transition.

I have a game field. I want when any object is in transition/moving, it cannot be touched.

I try to use isTouchEnabled = false or true to prevent the touch. But when there are many moving objects or timers,it’s not working properly.

What is the best method to prevent touch and how to detect if any object is moving then disable the touch.

Thank you so much :slight_smile:

Note: i can disable touch but when I continuously touch, that code is not working properly.

I’m not sure if your “isTouchEnabled” is a single variable, or a property on each object.

The way I would do it is to make “isTouchEnabled” a property of each object. Then right before you call transition.to(), set yourObject.isTouchEnabled = false.

Then transition.to(yourObject, {time=1000, x=100, y=200, onComplete=function() yourObject.isTouchEnabled=true end})

In your touch function, check if event.target.isTouchEnabled == true. And that should be it.

I apologise if the formatting is not correct in my post, I am posting from an iPad and it doesn’t seem to be inserting line breaks :frowning:

Except this time, when it did format correctly…

Thanks for the reply.

But I have many objects. (such as jewels in Bejeweled). So I want when an object move, nothing can be touched. That method doesn’t work with the timer.performWithDelay…

I think I can use for loop and check for all the object, but it’s not a good way because it may consume a lot of memory.

Do you have any idea?

Well in that case, just use a dingle variable rather than doing it per object:

local isTouchEnabled = true local function touchObject() if isTouchEnabled then isTouchEnabled = false transition.to(yourObject, {time=1000, y=yourObject.y+100, ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ onComplete=function() isTouchEnabled=true end } end end

Now, nothing can be touched until the transition has been finished.

I don’t see any reason why this wouldn’t work, based on what you’ve said so far.

I tried to use many methods but nothing works.

Because there are many objects’ in transition, thus when an object runs complete, each enables game play, so we can still touch it at that time.

I try to use a timer to delay enabling play again, and if there is a timer, cancel it, but it’s still not working.

timer.

   if(timerP) then
      timer.cancel(timerP)
   end

 timerP = timer.performWithDelay(600, enablePlay)

I need a way to detect if there is any transition, timer and specific function running, don’t enable the game play and just enable it once when all the transitions, functions finish.

How can i do this? thank you so much :slight_smile:

Ok , I think the easiest way will be to use my original idea of making the isTouchEnabled a property for each object. As before, set it to false at the start of the transition, and to true at the end. All of these objects will need to be in a table. Then iterate through the table in your touch function. If any of the objects have a false isTouchEnabled property, then do not process the rest of the touch function. local function touch (event) local canTouch = true for i =1, #myObjectTable do if myObjectTable[i].isTouchEnabled = false then canTouch = false end end if canTouch then --do your touch functionality here else return false end end

I’m not sure if your “isTouchEnabled” is a single variable, or a property on each object.

The way I would do it is to make “isTouchEnabled” a property of each object. Then right before you call transition.to(), set yourObject.isTouchEnabled = false.

Then transition.to(yourObject, {time=1000, x=100, y=200, onComplete=function() yourObject.isTouchEnabled=true end})

In your touch function, check if event.target.isTouchEnabled == true. And that should be it.

I apologise if the formatting is not correct in my post, I am posting from an iPad and it doesn’t seem to be inserting line breaks :frowning:

Except this time, when it did format correctly…

Thanks for the reply.

But I have many objects. (such as jewels in Bejeweled). So I want when an object move, nothing can be touched. That method doesn’t work with the timer.performWithDelay…

I think I can use for loop and check for all the object, but it’s not a good way because it may consume a lot of memory.

Do you have any idea?

Well in that case, just use a dingle variable rather than doing it per object:

local isTouchEnabled = true local function touchObject() if isTouchEnabled then isTouchEnabled = false transition.to(yourObject, {time=1000, y=yourObject.y+100, ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ onComplete=function() isTouchEnabled=true end } end end

Now, nothing can be touched until the transition has been finished.

I don’t see any reason why this wouldn’t work, based on what you’ve said so far.

I tried to use many methods but nothing works.

Because there are many objects’ in transition, thus when an object runs complete, each enables game play, so we can still touch it at that time.

I try to use a timer to delay enabling play again, and if there is a timer, cancel it, but it’s still not working.

timer.

   if(timerP) then
      timer.cancel(timerP)
   end

 timerP = timer.performWithDelay(600, enablePlay)

I need a way to detect if there is any transition, timer and specific function running, don’t enable the game play and just enable it once when all the transitions, functions finish.

How can i do this? thank you so much :slight_smile:

Ok , I think the easiest way will be to use my original idea of making the isTouchEnabled a property for each object. As before, set it to false at the start of the transition, and to true at the end. All of these objects will need to be in a table. Then iterate through the table in your touch function. If any of the objects have a false isTouchEnabled property, then do not process the rest of the touch function. local function touch (event) local canTouch = true for i =1, #myObjectTable do if myObjectTable[i].isTouchEnabled = false then canTouch = false end end if canTouch then --do your touch functionality here else return false end end