Button on off tap

I can’t find in this doc - https://docs.coronalabs.com/api/library/widget/newButton.html - how to set the button just pressed by tap number uno, and in any other moment set the button released by tap number duo. Like simple switchers, you know. Because. Help. ASAP. I’ve been waiting patiently… Please :confused:

PS. It should be a 2-image button, of course. For sure.
PPS. I have 24 buttons in my app, the pressed buttons show some kind of a pattern for a gamer, but I cannot lock tne f. buttons in a pressed position.

Do you mean a toggle button/checkbox?

  1. Press + release to select.
  2. Press + release to deselect

https://docs.coronalabs.com/api/library/widget/newSwitch.html

The same button can be used for radio buttons too.

@roaminggamer, no, look at your keybord, you make “press+release” to print a symbol. I need a 2-image button animation, like a switcher, the first tap = button was pressed, then the second tap = button was released:

Screenshot_2

PS. Is there any chance not to use “style = onOff” and image sheets, that’s the questioon…

PPS. Cause it takes plenty of time.

PPPS. I’m too lazy? NO, but there are a lot of buttons!

I nave some “worlds”, every one is marked by a unique sign. A gamer must activate some signes to build a “transport chain” among those worlds. Something like this:

Well, I solved it. See you.

What was your solution, in case someone else has the same problem in future?

Personally I would have changed the .fill property of the button when it is in the “pressed” state.

@alanFlickGames oh, it is very monstrous code, close your eyes and never use it, especially on Monday:

Modes = {}

Modes.greenLever = false
Modes.yellowLever = false 

– etc.

Levers = {}

Levers.greenLeverOn = display.newImageRect ("green_lever_on.png", width, height)
Levers.greenLeverOn.x = ...
Levers.greenLeverOn.y = ...

Levers.greenLeverOff = display.newImageRect ("green_lever_off.png", width, height)
Levers.greenLeverOff.x = Levers.greenLeverOn.x
Levers.greenLeverOff.y = Levers.greenLeverOn.x

Status = {}

Status.greenLeverOn = function ()
 Levers.greenLeverOff.isVisible = false
 print ("Hey, the green lever is on!")
 Modes.greenLever = true
end

Levers.greenleverOff.tap = Status.greenLeverOn
Levers.greenleverOff:addEventListener ("tap", Status.greenLeverOn)

Status.greenLeverOff = function ()
 Levers.greenLeverOff.isVisible = true
 print ("Hey, the green lever is off!")
 Modes.greenLever = false 
end

Levers.greenLeverOn.tap = Status.greenLeverOff
Levers.greenLeverOn:addEventListener ("tap", Status.greenLeverOff)

etc. the same for every lever…

Now, next step ==>>

Status.CompareYellowGreen = function ()
 if  Modes.yellowLever == true and
     Modes.greenLever == true then

     print ("Welcome to YelloGreen World!")

     elseif Modes.yellowLever == false or Modes.greenLever == true then
              
               print ("It's a final countdown!")

 end
return true
end

Runtime:addEventListener ("enterFrame", Status.CompareYellowGreen)

Well, it is some like this, but I can’t guarantee this mess works everywhere in the entire Universe.

PS. Read this doc to get less work: https://docs.coronalabs.com/api/type/CoronaPrototype/new.html

PPS. Finally, I’ll prefer a combination of switchers and radiobuttons… Ok, @roaminggamer, you won.

Actually what you describe is what I also described.

Your tap is the equivalent of a touch + release. Unless you’re holding your finger on the screen forever.

Tip: I would suggest NOT using the tap listener/event for buttons. ‘touch’ is a more complete and useful event. ‘tap’ is meant for very basic interactions and is hard to build upon for more complex interactions.

@isTrigger

I know you have a solution, but I still think it is worth posting some examples later, so I will.

Check back in later today. I should have time to post some basic examples to help you simplify toggle and radio button creation using two images.

@isTrigger

https://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2020/07/buttonHelp.zip

This zip file contains two separate examples.

One uses SSK to make push, toggle, radio buttons.

The second one supplies a basic module that creates the same types of buttons. It is less robust than the SSK button maker, but far simpler.

1 Like

@isTrigger - BTW. Nice screenshot.

1 Like