Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Image changing in buttons
Started by Enhiis May 19 2019 10:18 AM

3 replies to this topic
buttons help newbie
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

Enhiis

[GLOBAL: userInfoPane.html]
Enhiis
  • Observer

  • 1 posts
  • Corona SDK

Hello Corona Devs! I am newbie and I need your experienced help with buttons. I know that in Corona we can use widget.newButton with parametrs defaultFile and overFile. But what if I need more than 2 images? For example for creating soundOff and soundOn buttons or button that will change language of my game.



[TOPIC: post.html]
#2

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Contributor

  • 731 posts
  • Corona SDK

Hello and welcome to the community!

I usually create buttons like that out of two parts. First, I'd create the button itself (this could be that 2 image button of yours). This button itself doesn't need to change at all. Second, I'd add an image on top of the button, e.g. sound on graphic. Then, when the button is pressed, I'd change the graphic on top of the button from sound on to sound off. Same with languages or other types of buttons.

This is just one method of doing this. How you change the graphic is also completely up to you. You could create all of the buttons and just toggle alpha values between them, or destroy existing graphic and recreate a new one, or perhaps the simplest, create a sprite and just change the frame (or fill) of the image.



[TOPIC: post.html]
#3

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,571 posts
  • Corona SDK

@Xedur@Spyric - Is right.  This is probably best solved DIY.

 

However, SSK does have 2, 3, and 4 state image buttons which might be useful.  However, DIY is probably the best and simplest way to go.

 

https://roaminggamer.github.io/RGDocs/pages/SSK2/libraries/easy_interfaces/



[TOPIC: post.html]
#4

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,571 posts
  • Corona SDK

By the way,  You have described a two-state button. Sound on, sound off, can easily be achieved with widget buttons.




[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: buttons, help, newbie