This page is out of date

You've reached a page on the Ren'Py wiki. Due to massive spam, the wiki hasn't been updated in over 5 years, and much of the information here is very out of date. We've kept it because some of it is of historic interest, but all the information relevant to modern versions of Ren'Py has been moved elsewhere.

Some places to look are:

Please do not create new links to this page.

Blink And Lip Flap

What do you do if you've got a character and you want her eyes to occasionally blink, and you want her mouth to move when she's speaking?

First add the lip flap code to a separate part of your script:

init python:
    # This is set to the name of the character that is speaking, or
    # None if no character is currently speaking.
    speaking = None
    # This returns speaking if the character is speaking, and done if the
    # character is not.
    def while_speaking(name, speak_d, done_d, st, at):
        if speaking == name:
            return speak_d, .1
            return done_d, None
    # Curried form of the above.
    curried_while_speaking = renpy.curry(while_speaking)
    # Displays speaking when the named character is speaking, and done otherwise.
    def WhileSpeaking(name, speaking_d, done_d=Null()):
        return DynamicDisplayable(curried_while_speaking(name, speaking_d, done_d))
    # This callback maintains the speaking variable.
    def speaker_callback(name, event, **kwargs):
        global speaking
        if event == "show":
            speaking = name
        elif event == "slow_done":
            speaking = None
        elif event == "end":
            speaking = None
    # Curried form of the same.
    speaker = renpy.curry(speaker_callback)

Next, define the character and the character image. Split the character image into body, eyes and mouth when you draw it. (359, 927) is the length and height of the character. (101, 50) is the X and Y offset from the top left corner for the blinking eyes, while (170, 144) is the X and Y offset for the moving mouth.

If your eye and mouth layers are the same size as the character themselves, the X and Y offset should be (0, 0).

 # Create such a character.
 define girl = Character("Girl", callback=speaker("girl"))
 # Composite things together to make a character with blinking eyes and
 # lip-flap.
 image girl normal = LiveComposite(
    (359, 927),
    (0, 0), "base.png",
    (101, 50), "girl eyes normal",
    (170, 144), WhileSpeaking("girl", "girl mouth normal", "mouth_closed.png"),

 image girl eyes normal:
    # This randomizes the time between blinking.

 image girl mouth normal:

Now the defined character will talk automatically and blink their eyes. If you want just the lip flap, remove "girl eyes normal" and the corresponding code from the LiveComposite.

 # The game starts here.
 label start:
    scene black
    show girl normal
    "Not speaking."
    girl "Now I'm speaking. Blah blah blah blah blah blah blah."
    "Not speaking any more."
    girl "Now I'm speaking once again. Blah blah blah blah blah blah blah."

This code was adapted from the original by PyTom on this thread.