Textbutton Image?

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
iDweadith
Regular
Posts: 63
Joined: Sun Mar 01, 2020 4:15 pm
Contact:

Textbutton Image?

#1 Post by iDweadith »

Hello guys!

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

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Textbutton Image?

#2 Post by trooper6 »

Create a screen that has the image on it. Have the button show the screen.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
iDweadith
Regular
Posts: 63
Joined: Sun Mar 01, 2020 4:15 pm
Contact:

Re: Textbutton Image?

#3 Post by iDweadith »

Thanks trooper6

So, is it the only way?

I mean I'll need too many screens

User avatar
isobellesophia
Miko-Class Veteran
Posts: 979
Joined: Mon Jan 07, 2019 2:55 am
Completed: None
Projects: Maddox and Friends! (AI Teacher friend), Friendly Universities! (Soon)
Organization: Friendly Teachers series
Deviantart: SophBelle
itch: Child Creation
Location: Philippines, Mindanao
Contact:

Re: Textbutton Image?

#4 Post by isobellesophia »

Code: Select all

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

I am a friendly user, please respect and have a good day.


Image

Image


User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Textbutton Image?

#5 Post 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.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
iDweadith
Regular
Posts: 63
Joined: Sun Mar 01, 2020 4:15 pm
Contact:

Re: Textbutton Image?

#6 Post 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

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: Textbutton Image?

#7 Post 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

Frameworks & Scriptlets:

User avatar
iDweadith
Regular
Posts: 63
Joined: Sun Mar 01, 2020 4:15 pm
Contact:

Re: Textbutton Image?

#8 Post by iDweadith »

Guys, I really love you

It works perfectely thanks, thanks, thanks

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Ocelot, WladekProd