How to make a button inactive?

Hello,

I just want to make a button inactive after my 1st move and enable it back again for my 3rd move.For 2nd move that button should be inactive and i want other button to be active.Its like tic tac toe game and here button i am referring is actually an image i am using as a button.Is it possible?If yes please help.

Sure. Use a variable to hold a count of the number of times the button has been pushed. Start it at 0.

I’m going to assume you’re responding to touch events and not tap events.  In your touch handler, do something like:

local count = 0 local function touchHandler( event )     if event.phase == "ended" then          count = count + 1          if count == 1 then               count = 0               return true          end          -- the rest of your code     end end

Or something like that.

Rob

Thank u Rob.One more thing,I have 2 different game pieces which i dont want to be placed in the same region when i touch that region.What i mean is like in tictactoe i dont want circle and cross to be overlapping.I want only one game piece to be in that region.Is there any way to do it or any function to say that region is occupied?Thank u again…

You might want to check out this tutorial:

https://coronalabs.com/blog/2013/07/23/tutorial-non-physics-collision-detection/

It provides a couple of functions that let you detect when objects are overlapping.

Rob

Thank u rob.Is it okay to ask questions in this topic only or should i make separate threads for different questions?

Search the forums and Google as well for your question first.  There is a very high chance it’s been asked before.  Then start a new thread or ask on an existing one.

Thanks

Rob

Are there any free resources like themes,buttons and more which we can use in our project?

Sure. Use a variable to hold a count of the number of times the button has been pushed. Start it at 0.

I’m going to assume you’re responding to touch events and not tap events.  In your touch handler, do something like:

local count = 0 local function touchHandler( event )     if event.phase == "ended" then          count = count + 1          if count == 1 then               count = 0               return true          end          -- the rest of your code     end end

Or something like that.

Rob

Thank u Rob.One more thing,I have 2 different game pieces which i dont want to be placed in the same region when i touch that region.What i mean is like in tictactoe i dont want circle and cross to be overlapping.I want only one game piece to be in that region.Is there any way to do it or any function to say that region is occupied?Thank u again…

You might want to check out this tutorial:

https://coronalabs.com/blog/2013/07/23/tutorial-non-physics-collision-detection/

It provides a couple of functions that let you detect when objects are overlapping.

Rob

Thank u rob.Is it okay to ask questions in this topic only or should i make separate threads for different questions?

Search the forums and Google as well for your question first.  There is a very high chance it’s been asked before.  Then start a new thread or ask on an existing one.

Thanks

Rob

Are there any free resources like themes,buttons and more which we can use in our project?