Text position problem in textbox

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
shuen
Regular
Posts: 72
Joined: Tue Mar 22, 2011 2:36 pm
Contact:

Text position problem in textbox

#1 Post by shuen » Sun Mar 25, 2012 2:09 am

Here is my code:

Code: Select all

init:
   $ left_text_normal = Character(None,
       window_background = Frame("gfx/textbox01.png", 0, 0),
       window_xfill=False,
       window_xminimum=540,
       window_yminimum=225,
       window_xalign=0.15,
       window_yalign=0.8,
       window_left_padding = 75,
       window_right_padding = 75,
       window_top_padding = 65,
       window_bottom_padding = 65,
       what_color="#000000", 
       what_size=16,
       what_xpos = 0.5,
       what_xmaximum =400)
   $ right_text_normal = Character(None,
       window_background = Frame(im.Flip("gfx/textbox01.png", horizontal=True), 0, 0),
       window_xfill=False,
       window_xminimum=540,
       window_yminimum=225,
       window_xalign=0.85,
       window_yalign=0.8,
       window_left_padding = 75,
       window_right_padding = 75,
       window_top_padding = 65,
       window_bottom_padding = 65,
       what_color="#000000",
       what_size=16,
       what_xpos = 0.5,
       what_xmaximum =400)
label start:
    left_text_normal "Text test. Text test. Text test. Text test. Text test. Text test. Text test. Text test. Text test. Text test. Text test. Text test. Text test. "
    right_text_normal "Text test. Text test."
    return
Both text can't place in the center of the textbox.
text1.jpg
text2.jpg
There should be something wrong with what_xpos = 0.5,
I tried what_xalign = 0.5 but the text show same as what_xalign = 0.0
Image
.Traditional Chinese Site.
~Illustrator+Graphic/Web Designer~

lackofwords
Newbie
Posts: 10
Joined: Sun Mar 18, 2012 5:41 pm
Contact:

Re: Text position problem in textbox

#2 Post by lackofwords » Sun Mar 25, 2012 4:18 pm

I don't know why, but for some reason 'pos' in this case does not want to take in absolute values. So you have to define the integer value of the position you want it to fit in.

So you want half the window size, which for your case is x 270 and y 112. Remember, it is only taking integer values for the pixel alignment, so you can't have a number like 112.5.
You could write it out with xpos = 270, xanchor = 0.5, but xcenter = 270 does the same thing with one line.

I've commented out the padding, because it seems a bit odd... It doesn't seem to be padding the right places. Such as, window_xpadding = #, gives the same # value padding on both left and right side. However, for some reason the right padding does not seem to apply itself. Could be something with the defining window size. Also, could be the same reason why 'pos' isn't working properly for defining an absolute position inside the window. My guess is it might be something with how window max and min size has to also account for padding and margin.

Anyhow, you could just use what_xmaximum to define a pseudo padding. Although, technically it is just limiting the width of the text, but it'll still serve the same functionality if your end goal was to have the text to be dead center of the text bubble.

So something like this;

Code: Select all

init:
    $ left_text_normal = Character(None,
    window_background = Frame("gfx/textbox01.png", 0, 0),
    window_xfill=False,
    window_xmaximum=540,
    window_xminimum=540,
    window_yminimum=225,
    window_ymaximum=225,
    window_xalign=0.15,
    window_yalign=0.8,
    #window_left_padding = 75,
    #window_right_padding = 75,
    #window_top_padding = 65,
    #window_bottom_padding = 65,
    what_color="#000000",
    what_size=16,
    what_xcenter = 270,
    what_ycenter = 112,
    what_xmaximum = 400
    )
    $ right_text_normal = Character(None,
    window_background = Frame(im.Flip("gfx/textbox01.png", horizontal=True), 0, 0),
    window_xfill=False,
    window_xminimum=540,
    window_xmaximum = 540,
    window_yminimum=225,
    window_ymaximum=225,
    window_xalign=0.85,
    window_yalign=0.8,
    #window_left_padding = 75,
    #window_right_padding = 75,
    #window_top_padding = 65,
    #window_bottom_padding = 65,
    what_color="#000000",
    what_size=16,
    what_xcenter = 270,
    what_ycenter = 112,
    what_xmaximum = 400
    )

label start:
    left_text_normal "Test text. Test text. Test text. Test text. Test text. Test text. Test text. Test text. Test text. Test text. Test text."
    right_text_normal "Test text."
    return
Attachments
renpy 2012-03-25 16-38-33-10.png
renpy 2012-03-25 16-38-33-10.png (8.6 KiB) Viewed 342 times
renpy 2012-03-25 16-38-32-31.png
renpy 2012-03-25 16-38-32-31.png (11.17 KiB) Viewed 342 times

Post Reply

Who is online

Users browsing this forum: No registered users