How to animate the text to gradually change in colour?

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
texi
Newbie
Posts: 14
Joined: Tue May 30, 2017 3:40 pm
Contact:

How to animate the text to gradually change in colour?

#1 Post by texi »

Is there a way to make the text gradually change in colour? I want to use this to indicate character health in combat.

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: How to animate the text to gradually change in colour?

#2 Post by xavimat »

You can't change gradually the color in front of the player, but you can have the color of the text checked every time that text is shown to the player.

I guess it's tricky.
Do you need the change on the normal text that the character says, or in a screen that you have made?
You need to go to the screen that have that text and "color" that text with some variable that you change somewhere, according the health.

A simply (and ugly) example:

Code: Select all

default health = 255
label start:
    "Hello, world."
    $ health -= 60
    e "You've created a new Ren'Py game."
    $ health -= 60
    e "Once you add a story, pictures, and music, you can release it to the world!"
    return
In the file "screens.rpy", look for the screen "say":

Code: Select all

screen say(who, what):
And change the line

Code: Select all

        text what id "what"
with:

Code: Select all

        text what id "what" color (255, health, health)
Every time the health changes, the color of the next text will tend to "red".
In this example, every character will be affected. You need an "if" statement inside the screen to avoid that.
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
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: How to animate the text to gradually change in colour?

#3 Post by Remix »

The Ren'py Color object supports a lot of colour mangling options

Example with interpolate...

Code: Select all

default colour_base = "#FF0000"
default colour_top = "#00FF00"
default colour_refs = [0.0, 0.01]

screen colour_test():
    python:
        colour_refs[1] = colour_refs[1] if 0.0 <= colour_refs[0] <= 1.0 else 0 - colour_refs[1]
        colour_refs[0] += colour_refs[1]
        ref_colour = Color( colour_base )
        #
        # this basically takes our ref_colour object ( with colour_base ) and pushes 
        # it toward the colour_top using a floating point fraction (0.0 to 1.0) to 
        # determine the final used colour
        #
        used_colour = ref_colour.interpolate( colour_top, colour_refs[0] )
    text "{0}%".format(round(colour_refs[0]*100)) color used_colour
    timer 0.1 action (renpy.restart_interaction) repeat True

label start:
    show screen colour_test
    "First Line"
Frameworks & Scriptlets:

texi
Newbie
Posts: 14
Joined: Tue May 30, 2017 3:40 pm
Contact:

Re: How to animate the text to gradually change in colour?

#4 Post by texi »

I'm trying to change the colour of the name of the character.

Post Reply

Who is online

Users browsing this forum: Bing [Bot]