Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Best way to swap images for a button?
Started by elifares Apr 25 2018 07:02 PM

4 replies to this topic
button widget swapping images newimagerect

Best Answer roaminggamer , 25 April 2018 - 07:28 PM

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.

[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

elifares

[GLOBAL: userInfoPane.html]
elifares
  • Enthusiast

  • 86 posts
  • Corona SDK

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.



[TOPIC: post.html]
#2

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,613 posts
  • Corona SDK

  Best Answer

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.



[TOPIC: post.html]
#3

elifares

[GLOBAL: userInfoPane.html]
elifares
  • Enthusiast

  • 86 posts
  • Corona SDK

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.



[TOPIC: post.html]
#4

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,613 posts
  • Corona SDK

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.

 

3. 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.



[TOPIC: post.html]
#5

SGS

[GLOBAL: userInfoPane.html]
SGS
  • Corona Geek

  • 2,131 posts
  • Corona SDK


[topic_controls]
[/topic_controls]