Centering text inside a frame [solved]

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
Hoomst
Newbie
Posts: 10
Joined: Wed Jun 08, 2022 9:46 am
Contact:

Centering text inside a frame [solved]

#1 Post by Hoomst »

I have a small image on which I'd like to display a centered text.
I figured using a frame with the image as the background would be an easy way to do that
While I can use xpos and ypos to adjust the position of the text, xalign and yalign don't seem to do anything.

What's the best way to have an image with a centered text on top?

Code: Select all

screen hud:
    frame:
        xpadding 0 ypadding 0
        if days == 1:
            background "GameUI/HUD/day_counter_1.png"
        else:
            background "GameUI/HUD/day_counter_2.png"  
        text "Day [days]":
            xalign 0.5 yalign 0.5
            style "qsb26"
Last edited by Hoomst on Wed Sep 28, 2022 6:28 am, edited 1 time in total.

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2400
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Centering text inside a frame

#2 Post by Ocelot »

Set frame size explicitely. By default frame will be just as large as largest child, in your case it would be as large, as contained text. Text is not moved, because there is no place for it to move.
< < insert Rick Cook quote here > >

laure44
Regular
Posts: 84
Joined: Mon Mar 08, 2021 10:55 pm
Projects: Arkan'sTower, Gemshine Lorelei!
Location: France
Contact:

Re: Centering text inside a frame

#3 Post by laure44 »

You can also use fixed.

Code: Select all

fixed fit_first True:
    add "an image"
    text "a text"

Post Reply

Who is online

Users browsing this forum: Google [Bot]