Short example of having an animation occur while a character is talking, such as blinking or mouth movement.


DMR beta

The DMR beta is still ongoing, and all routes are available to play. If you want to join in, be sure to subscribe to the Throne tier on our Patreon!

Ren’Py character talking animation

We received a question about adding lip flap animation while a character is talking, so here’s a short example. It works with layeredimages by treating them the same as an image. We haven’t benchmarked it to see if doing it this way makes you lose out on the predicting/optimization powers of layeredimages, however. If you benchmark it, we’d love to hear about the results.

taza talking on screen with the name sylvie, where his mouth is moving during dialogue

Define the base sprite (layeredimage).

layeredimage taza_base:
    always "images/sprites/taza/resize/base.png"

    if taza_bow:
        "images/sprites/taza/resize/bow.png"

    group mouth prefix "m":
        attribute n default "images/sprites/taza/resize/mouth_neutral.png" #at Transform(yoffset=-139,xoffset=103)
        

Define the animated image.

image taza talking:
    "taza m_n"
    pause .25
    "taza m_5"
    pause .3
    "taza m_4"
    pause .2
    repeat

Define the lip flap callback event.

init python:
    def taza_lip_flap(event,**kwargs):
        # when the dialogue event is over, set Taza to neutral mouth.
        # we don't want him to continue moving his mouth when others
        # are speaking.
        if event == "end":
            renpy.show("taza m_n")
        # show the animated image
        else:
            renpy.show("taza talking")

Define the character.

define t = Character(_("Sylvie"),callback=taza_lip_flap,image="taza")

Use the character.

label start:
    ""
    show taza
    "hello the weather is nice"
    t "Lorem ipsum"
Code adapted from Mkol103 on the LemmaSoft forums.

Questions or Comments?

Feel free to send in any AG-related questions! Our Ask Box is always open.

Thanks so much for all of your amazing support, and stay safe out there!