Ren'Py Namebox rotation changes position

Mr. TurTur

Newbie
Jun 12, 2020
85
75
This is the code I use to rotate my namebox.
It works, but each name has a slightly different position.
I think it is related to the length of the name.
Does anyone have an idea how I can fix this?


Python:
transform NameRotation:   
    rotate -5

screen say(who, what):
    style_prefix "say"

    window:
        id "window"

        if who is not None:

            window:
                id "namebox"
                style "namebox"
                text who id "who" at NameRotation


        text what id "what"

I thought it might be about the nameboxs rotation point relative to the textbox.



Screenshot 2022-09-30 013152.png Screenshot 2022-09-30 013138.png Screenshot 2022-09-30 013210.png
 

osanaiko

Engaged Member
Modder
Jul 4, 2017
2,296
3,953
I guess you got your code from

One point: the underlying "box" where the say name is rendered is still a rectangle at a certain position. It's tricky to get this to align with the image you have drawn.

In this case I suspect your problem is due to the "anchor" around which the rotation is calculated. Look at the docs:

It seems the default anchor is 0,0 (top left of the container). You probably want to change the anchor to (0.5, 0.5) which is the centre of container, and then also set the x and y pos so that the centre of the container is aligned with the centre of the name box space of your image.

And also this thread mentions the need to perhaps use "rotate_pad", which appears to be related to how the changing length of the text could affect the rotation...??:


One idea to help you debug: try adding a temporary style to the namebox that gives a background color. this will then show you the size/position/angle so you can debug.
 

Mr. TurTur

Newbie
Jun 12, 2020
85
75
Hey, thank you.

Coloring the box helped.

It was one of those problems where you feel stubid afterwards :D

Code:
## The width, height, and borders of the box containing the character's name, or
## None to automatically size it.
define gui.namebox_width = 300
define gui.namebox_height = 70
The automatic sizing f'ed everything up.
 
  • Like
Reactions: osanaiko

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,369
15,285
Python:
            window:
                id "namebox"
                style "namebox"
                text who id "who" at NameRotation
Why apply the transform only to the text ?

Python:
            window:
                at NameRotation
                id "namebox"
                style "namebox"
                text who id "who"
Would ensure that, since the transform is applied to the containing box, everything stay put.