Page 1 of 1

Change narration text color with background

Posted: Fri Feb 23, 2018 12:24 am
by Moxanthia
Hiya, I'm trying to make a simple text-based game with Ren'Py. Some scenes take place on Earth and some in space. The scenes in space have a black background, while the ones on Earth have a white background. This being the case, I need to constantly switch between white and black narration text, respectively. It seems that I could use this: https://www.renpy.org/doc/html/gui_adva ... ui-rebuild I'm new to coding though, so I have no clue how this would work for my specific case.

Re: Change narration text color with background

Posted: Fri Feb 23, 2018 12:33 am
by Draziya
You could always define a second narrator for the black text:

Code: Select all

define black = Character (None, what_color="#000")

Re: Change narration text color with background

Posted: Fri Feb 23, 2018 12:52 am
by Moxanthia
Yeah. I was just looking for a way to not have to write black before everything.

Re: Change narration text color with background

Posted: Fri Feb 23, 2018 12:54 am
by Lezalith
So, this is the default say() screen in screens.rpy file. Say screen is the screen that contains a textbox, a name, a dialogue... All that fancy stuff:

Code: Select all

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

    window:
        id "window"

        if who is not None:

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

        text what id "what"


    ## If there's a side image, display it above the text. Do not display on the
    ## phone variant - there's no room.
    if not renpy.variant("small"):
        add SideImage() xalign 0.0 yalign 1.0
Now, long story short, it basically takes the name of the character talking ("who") and the dialogue ("what") and displays it in some windows.
Focus on the text what id "what" , that is the line that displays the dialogue. First, let's branch it out onto multiple lines by adding a colon.

Code: Select all

text what:
    id "what"
Now we need something that will determine the color used. For this, we will use a simple variable.

Code: Select all

text what:
    id "what"
    if colorOfText == "white":
        color "#FFFFFF"
    else:
        color "#FF0000"
This simple code will add the "color" tag to our text, changing the color. But remember, variables always need to be defined before they are used. And because we need it defined before the screens are defined, we need to put it into init block.
Just outside of the screen, behind if not renpy.variant..., like this:

Code: Select all

    if not renpy.variant("small"):
        add SideImage() xalign 0.0 yalign 1.0

init -2 python:
    colorOfText = "white"


This will set the variable to "white" by default. Currently, it will show white text, and if we were to change that variable to anything else with $ colorOfText = "something", the text will turn red (#FF0000). Of course, you can customize this by changing the if/else branch.

Re: Change narration text color with background

Posted: Fri Feb 23, 2018 1:25 am
by Moxanthia
Thanks much!