Visual "Action" for Buttons with Only One Image?

Making an up and down version of a button is tedious and stupid. It’s 2016 and while personal jetpacks are still not here, doing something manually that the computer could do is boring.

If CL allowed fillColor as a parameter for an image button we could just create the Up version of a button and be done – the fillColor could darken the button when it’s pressed.

I can get most of the way there with this in my onEvent handler:

if event.phase == "began" then event.target:setFillColor( 0.8, 0.8, 0.8 ) end if event.phase == "cancelled" or event.phase == "ended" then event.target:setFillColor( 1, 1, 1 ) end

…but it offends me that I have to do that (I’m very sensitive). Plus, the button doesn’t act correctly when the mouse is still down but the cursor/finger has been dragged off the button.

Since the shape button can work with the fillColor parameter, shouldn’t the image be able to, as well?

Or, is there another (easy) way to accomplish this?

 Jay

You have a couple of options. You could get the source code from our github account (https://github.com/coronalabs/framework-widget) and add the feature yourself to widget.newButton().

Since you’re using an image, you could write your own button making function that does what you need. Under the hood widget.newButton actually assigns the touch handler to itself and when it gets an event it passes the event on to the defined handler after doing it’s actions. In other words the listener provided for onEvent, onRelease or onPressed isn’t the actual “touch” event. The widget takes the touch event, does it’s color changing and then sends the event table on to your listener. There’s no reason you can’t do this in your own button class.

Rob

Thanks, Rob. I’ll play around with that. While I love Corona more, using Unity for the past year has spoiled me in some ways, such as only needing a single image for a button. It’s the little things. :wink:

 Jay

You have a couple of options. You could get the source code from our github account (https://github.com/coronalabs/framework-widget) and add the feature yourself to widget.newButton().

Since you’re using an image, you could write your own button making function that does what you need. Under the hood widget.newButton actually assigns the touch handler to itself and when it gets an event it passes the event on to the defined handler after doing it’s actions. In other words the listener provided for onEvent, onRelease or onPressed isn’t the actual “touch” event. The widget takes the touch event, does it’s color changing and then sends the event table on to your listener. There’s no reason you can’t do this in your own button class.

Rob

Thanks, Rob. I’ll play around with that. While I love Corona more, using Unity for the past year has spoiled me in some ways, such as only needing a single image for a button. It’s the little things. :wink:

 Jay