Dynamic style for buttons

Hi all,

My scenario is :

I have four buttons.

Everytime i press a button, I want to change the look and style of all the buttons ( default image, font, font style ).

I know we can NOT change these properties during run time, and have tried some workarounds :

Use images with image sheets for buttons, 4 newtexts on top of them, each with different font.

I can change the images during run time, and i rearrange the positions of the texts onto different buttons.

I can then change the font size also, so this works quite well but I am limited to always using exactly that 4 fonts.

Use widget buttons and recreate them ( Have not tried this out )

removeSelf and create the buttons again. I am not sure how to add them to the main group of the scene though, as I’m not sure how to access this in a button listener.

I am wondering what would be the recommended way to do this, or is there a better way? 

Thanks in advance!

I’m not sure I would go the widget.newButton route.  We’ve made that API call rather powerful, but at the end of the day, it’s designed to work for native looking buttons.  It has powerful creation features, but limited change after creation features.

Since creating buttons using display.newImageRect() and adding a touch handler is pretty darn simple, you will probably want to go this route and go with the imagesheet.   We did a tutorial on swapping images that may help you:  https://coronalabs.com/blog/2013/11/26/tutorial-techniques-for-swapping-images/

Rob

Alright Rob thanks for the quick reply!

I’m not sure I would go the widget.newButton route.  We’ve made that API call rather powerful, but at the end of the day, it’s designed to work for native looking buttons.  It has powerful creation features, but limited change after creation features.

Since creating buttons using display.newImageRect() and adding a touch handler is pretty darn simple, you will probably want to go this route and go with the imagesheet.   We did a tutorial on swapping images that may help you:  https://coronalabs.com/blog/2013/11/26/tutorial-techniques-for-swapping-images/

Rob

Alright Rob thanks for the quick reply!