Page 1 of 1

Textbutton Image?

Posted: Tue Jun 16, 2020 11:15 pm
by iDweadith
Hello guys!

Is it possible to show an image by clicking in a textbutton?

Re: Textbutton Image?

Posted: Tue Jun 16, 2020 11:58 pm
by trooper6
Create a screen that has the image on it. Have the button show the screen.

Re: Textbutton Image?

Posted: Wed Jun 17, 2020 12:03 am
by iDweadith
Thanks trooper6

So, is it the only way?

I mean I'll need too many screens

Re: Textbutton Image?

Posted: Wed Jun 17, 2020 1:12 am
by isobellesophia

Code: Select all

screen mop():
    add "image.png" xalign 0.5 yalign 0.5
    textbutton "Return" action Hide("mop") xalign 1.0


Re: Textbutton Image?

Posted: Wed Jun 17, 2020 3:38 am
by trooper6
iDweadith wrote: Wed Jun 17, 2020 12:03 am Thanks trooper6

So, is it the only way?

I mean I'll need too many screens
Could you give more information about what the actual use case is? Because there may be more efficient ways to do what you want.
Also you can pass a variable to a screen, for example, you could pass an image to that screen. So, one screen, passing whichever image you need.

Re: Textbutton Image?

Posted: Wed Jun 17, 2020 8:25 am
by iDweadith
So, in my game I have a side menu made of textbuttons, in the center of the screen there is an image that I want to change when one of the buttons is clicked.

Something like if I click on "Happy Button" the centered image will change to "Happy image"

I can do it with screens but I'll need lots of them


Also I'm trying to use variable something like this:

Code: Select all

image mood = mood_img
define mood_img = "happy.png" 

screen mood_image:
    add "mood_img"

screen mood_screen:
    use mood_image
    vbox:
        xalign 0.90
        yalign 1.0
        textbutton "Happy" action SetVariable("mood_img", "happy.png")
        textbutton "Sad" action SetVariable("mood_img", "sad.png")
I don't know I'm a bit confused right now

Re: Textbutton Image?

Posted: Wed Jun 17, 2020 9:25 am
by Remix

Code: Select all

# variable with string value
default current_mood = "happy"

# using interpolation makes this image dynamic... it updates automatically to show the correct image
image mood = "images/[current_mood].png"

screen mood_image:
    add "mood"

screen mood_screen:
    use mood_image
    vbox:
        xalign 0.90
        yalign 1.0
        textbutton "Happy" action SetVariable("current_mood", "happy")
        textbutton "Sad" action SetVariable("current_mood", "sad")
        # Note we change the variable not the image
        # As the image is dynamic, it will pick up the change to the variable


Re: Textbutton Image?

Posted: Wed Jun 17, 2020 10:34 am
by iDweadith
Guys, I really love you

It works perfectely thanks, thanks, thanks