Best way to swap images for a button?

Hi,

I’m looking at Techniques for Swapping Images and I am wondering if any of those methods could be applied to the default image file in a newButton widget?

In my game, I have a weapon button which starts off blank or “empty” and when a player picks up a weapon, I want to display a different image as the weapon button to show they have something to shoot now.

Should I create a new button widget when the player picks up a weapon and then remove it when they shoot or should I use newImageRect as the empty weapon button and swap the images?

Any ideas from experienced game devs would be helpful.

Thanks.

This sounds like a re-ask of a prior question… at least it seems familiar.

The widget buttons do not supply a way to change the images after they are created.  You can however download the widget library code and modify it to allow this.

Alternately you can code your own widget library ( BEST ).

Alternately, you can simply delete the button and replace it with one that uses new art. ( EASIEST but not always suitable ).

Alternately, you can have two buttons and only show one at a time.

Thanks for the suggestions @roaminggamer. I didn’t know this was asked before, certainly not from me.

What about this alternative, using newImageRect and adding an EventListener using “tap” on it? Would that be better performance wise than creating two buttons and only showing one at a time?

Cheers.

  1. That’s fine.  I just felt like I saw this question in the last couple of weeks.

  2. That idea is the same as what I mean by:

 

Alternately you can code your own widget library ( BEST ).  i.e. Make your own button code.

 

  1. Performance is not an issue (unless you’re going to have 1000s of buttons?)  The only issues are ease-of-use and ease-of-implementation.

Or you could read the docs - https://docs.coronalabs.com/tutorial/media/swapImages/index.html

This sounds like a re-ask of a prior question… at least it seems familiar.

The widget buttons do not supply a way to change the images after they are created.  You can however download the widget library code and modify it to allow this.

Alternately you can code your own widget library ( BEST ).

Alternately, you can simply delete the button and replace it with one that uses new art. ( EASIEST but not always suitable ).

Alternately, you can have two buttons and only show one at a time.

Thanks for the suggestions @roaminggamer. I didn’t know this was asked before, certainly not from me.

What about this alternative, using newImageRect and adding an EventListener using “tap” on it? Would that be better performance wise than creating two buttons and only showing one at a time?

Cheers.

  1. That’s fine.  I just felt like I saw this question in the last couple of weeks.

  2. That idea is the same as what I mean by:

 

Alternately you can code your own widget library ( BEST ).  i.e. Make your own button code.

 

  1. Performance is not an issue (unless you’re going to have 1000s of buttons?)  The only issues are ease-of-use and ease-of-implementation.

Or you could read the docs - https://docs.coronalabs.com/tutorial/media/swapImages/index.html