[SOLVED] Imagebutton with text?

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
RicharDann
Veteran
Posts: 286
Joined: Thu Aug 31, 2017 11:47 am
Contact:

[SOLVED] Imagebutton with text?

#1 Post by RicharDann »

I was wondering if there is a way to have imagebuttons show a string over them? I'm making some menu buttons with text that can be translated, I've tried this:

Code: Select all

screen gm_menu():
    
    imagebutton _("Inventory") auto "gm_button_%s.png" action ShowMenu('inv_menu')
But obviously this didn't work. Is there a way to have text appear over an imagebutton?

I suppose I could use a textbutton, but how would I add an image below that would react to the button being hovered and unhovered so it changes like imagebuttons do automatically?
Last edited by RicharDann on Tue Oct 03, 2017 11:19 am, edited 1 time in total.
The most important step is always the next one.

User avatar
Donmai
Eileen-Class Veteran
Posts: 1960
Joined: Sun Jun 10, 2012 1:45 am
Completed: Toire No Hanako, Li'l Red [NaNoRenO 2013], The One in LOVE [NaNoRenO 2014], Running Blade [NaNoRenO 2016], The Other Question, To The Girl With Sunflowers
Projects: Slumberland
Location: Brazil
Contact:

Re: Imagebutton with text?

#2 Post by Donmai »

Images can also be translated.
https://www.renpy.org/doc/html/translat ... anslations
When translating a game, it may be necessary to replace a file with a translate version. For example, if an image contains text, it might make sense to replace it with a version of the image where the text is in another language.

Ren'Py handles this by looking in the translation directory for the image. For example, if the "piglatin" language is in use, and "library.png" is loaded, Ren'Py will use "game/tl/piglatin/library.png" in preference to "game/library.png".
Let's say your game is in English and you have your imagebuttons in game/images/imagebutons/
and your game has, say, a Russian translation, then you will put your Russian imagebuttons in
game/tl/russian/images/imagebuttons/.
Image
No, sorry! You must be mistaking me for someone else.
TOIRE NO HANAKO (A Story About Fear)

User avatar
RicharDann
Veteran
Posts: 286
Joined: Thu Aug 31, 2017 11:47 am
Contact:

Re: Imagebutton with text?

#3 Post by RicharDann »

So as I expected I have to make multiple copies every single imagebutton file for each translation. I didn't want to do it this way hoping to save some space. But now that I think about it, imagebuttons have really small size so it won't make that much of a difference. I'll go with this, thanks Donmai!
The most important step is always the next one.

User avatar
xavimat
Eileen-Class Veteran
Posts: 1461
Joined: Sat Feb 25, 2012 8:45 pm
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love
Organization: Pilgrim Creations
Github: xavi-mat
itch: pilgrimcreations
Location: Spain
Discord: xavimat
Contact:

Re: [SOLVED] Imagebutton with text?

#4 Post by xavimat »

Don't forget that you have the "button" in screens. imagebuttons and textbuttons are made from "button", but "button" is a fixed where you can add what you want: an image, a translatable text on top of it, another text on the corner, another image on the left..., and an "action" when anywhere on the button is clicked.
https://renpy.org/doc/html/screens.html#button
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

User avatar
Donmai
Eileen-Class Veteran
Posts: 1960
Joined: Sun Jun 10, 2012 1:45 am
Completed: Toire No Hanako, Li'l Red [NaNoRenO 2013], The One in LOVE [NaNoRenO 2014], Running Blade [NaNoRenO 2016], The Other Question, To The Girl With Sunflowers
Projects: Slumberland
Location: Brazil
Contact:

Re: [SOLVED] Imagebutton with text?

#5 Post by Donmai »

"Button" is a great interface statement. It's only lacking some good examples of usage in its documentation.
Image
No, sorry! You must be mistaking me for someone else.
TOIRE NO HANAKO (A Story About Fear)

User avatar
xavimat
Eileen-Class Veteran
Posts: 1461
Joined: Sat Feb 25, 2012 8:45 pm
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love
Organization: Pilgrim Creations
Github: xavi-mat
itch: pilgrimcreations
Location: Spain
Discord: xavimat
Contact:

Re: [SOLVED] Imagebutton with text?

#6 Post by xavimat »

Donmai wrote: Fri Oct 06, 2017 5:39 pm "Button" is a great interface statement. It's only lacking some good examples of usage in its documentation.
That.

In screens.rpy, in the screen file_slots(title) there are some examples of "button", one of them with a vbox inside of it. But they are a little advanced. I suggest to study those.
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

User avatar
RicharDann
Veteran
Posts: 286
Joined: Thu Aug 31, 2017 11:47 am
Contact:

Re: [SOLVED] Imagebutton with text?

#7 Post by RicharDann »

xavimat, you're totally right! At first I thought button was a kind of hotspot like on imagemaps I didn't imagine it could accept children, this will be indeed very useful, thank you!
The most important step is always the next one.

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: [SOLVED] Imagebutton with text?

#8 Post by Remix »

Another option (which retains all the benefits of imagebutton, such as alpha mask and the auto toggle for the images) is to just throw the imagebutton and text in a fixed...

Code: Select all

        fixed:
            imagebutton idle "images/btn.png" action Jump('nowhere') xpos 0 ypos 0
            text _("Translate Me") xpos 5 ypos 20
Frameworks & Scriptlets:

User avatar
RVNSN
Regular
Posts: 36
Joined: Mon Apr 08, 2019 3:54 pm
Projects: Lust & Piracy
itch: rvnsn
Contact:

Re: [SOLVED] Imagebutton with text?

#9 Post by RVNSN »

I'm missing something, neither of these worked for me. Could you show the code you got to work to display text over an imagebutton, please?

[UPDATE:]

After going back to it with a less weary brain, I finally got it to work using remix's method, as it required almost zero modification to my preexisting code.

The 2 following variations worked out just fine and dandy. And a screenshot to show it in use, if anyone else needs to see an example. Oh, and I used "textbutton" instead of "text", because I have it set to use a certain font.

A big thank you to everyone here!

Code: Select all

screen booty2():
    fixed:
        imagebutton xalign 0.01 ypos 650:
            idle "gui/treasure_chest_gui_idle.png"
            hover "gui/treasure_chest_gui_hover.png"
            action [Show ("booty"), Hide ("booty2")]
        textbutton _("{color=#000000}{size=-20}$[money]{/size}{/color}") xalign 0.085 ypos 760
OR, using the auto variant for imagebutton:

Code: Select all

screen booty2():
    fixed:
        imagebutton auto "gui/treasure_chest_gui_%s.png":
            xalign 0.01
            ypos 650
            action [Show ("booty"), Hide ("booty2")]
        textbutton _("{color=#000000}{size=-20}$[money]{/size}{/color}") xalign 0.085 ypos 760
Screen Shot 2019-12-09 at 11.40.57 PM.png

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Amazon [Bot], Google [Bot]