Editing/Changing a Widget Button's Default File

Most people love buttons. I’m no exception, and I use a ton of them. However, that doesn’t make me anything close to an expert. I’m wondering if it is possible to change a widget button’s image file(s) after the widget has been created. For example, I have a game piece that I would like to change the look of (image1.png to image2.png) during the game without having to remove and recreate the object. If this is possible, can someone share how it is done? 

Thanks bunches,

Nathan

The widget.newButton() API cannot do this. You have to destroy and re-create.  This should be fast enough it happens between frame updates, so there shouldn’t be any noticeable flicker.  But widget.newButton isn’t the only way to do buttons.  If you do other variants, you can use this tutorial to help you with swapping images:

https://coronalabs.com/blog/2013/11/26/tutorial-techniques-for-swapping-images/

Rob

Thanks, Rob! I guess I won’t worry about changing the widget’s image. That blog post is tremendous, and there is plenty in there that gave me great ideas on how to handle my situation with ease. 

Nathan

The widget.newButton() API cannot do this. You have to destroy and re-create.  This should be fast enough it happens between frame updates, so there shouldn’t be any noticeable flicker.  But widget.newButton isn’t the only way to do buttons.  If you do other variants, you can use this tutorial to help you with swapping images:

https://coronalabs.com/blog/2013/11/26/tutorial-techniques-for-swapping-images/

Rob

Thanks, Rob! I guess I won’t worry about changing the widget’s image. That blog post is tremendous, and there is plenty in there that gave me great ideas on how to handle my situation with ease. 

Nathan