Ren'Py memo

Ren'Pyの個人的なメモ

ボイス中だけ口パクをする

引用:Can Lip Flap Be Synched (Sync / Synced) With Voice [solved] - Lemma Soft Forums


layaredimageの立ち絵で

ボイスが鳴っている最中だけ

ATLの口パクアニメーションを動かす

コードです。



options.rpy

python early:

    # https://lemmasoft.renai.us/forums/viewtopic.php?t=25399
    speaking = None

    def while_speaking(names, speak_d, done_d, st, at):
        if renpy.music.is_playing('voice') and speaking == names and _preferences.get_mute("voice") == False:
            return speak_d, .1
        else:
            return done_d, None

    curried_while_speaking = renpy.curry(while_speaking)

    def WhileSpeaking(names, speaking_d, done_d=Null()):
        curried_while_speaking = renpy.curry(while_speaking)
        return DynamicDisplayable(curried_while_speaking(names, speaking_d, done_d))

    def speaker_callback(names, event, **kwargs):
        global speaking
        speaking = names

    speaker = renpy.curry(speaker_callback)

script.rpy

    define b = Character(_('スーくん'), kind=a,voice_tag="b",who_color=gui.color4,callback=[speaker("b"), name_callback],image="1",what_color=gui.color4, cb_name = "1")

    define c = Character(_('サネちゃん'), kind=a,voice_tag="c",who_color=gui.color4, image="2",what_color=gui.color4, callback=[speaker("c"), name_callback], cb_name = "2")

voice_tagとcallbackのspeaker("(任意の名前指定)")が重要箇所です。
オートハイライト機能と併用しているのでcallbackをリストにしています。
併用していない場合はcallback=speaker("b")などでいいと思います。

images.rpy

init -2:

    image 1_talk:
        choice:
            "1_c_c6"
        choice:
            "1_c_c7"
        choice:
            "1_c_c1"
        pause 0.1
        choice:
            "1_c_c6"
        choice:
            "1_c_c7"
        choice:
            "1_c_c1"
        pause 0.1
        choice:
            "1_c_c6"
        choice:
            "1_c_c7"
        choice:
            "1_c_c1"
        pause 0.1
        repeat

    image 1_talk3:
        choice:
            "1_c_c31"
        choice:
            "1_c_c32"
        choice:
            "1_c_c3"
        pause 0.1
        choice:
            "1_c_c31"
        choice:
            "1_c_c32"
        choice:
            "1_c_c3"
        pause 0.1
        choice:
            "1_c_c31"
        choice:
            "1_c_c32"
        choice:
            "1_c_c3"
        pause 0.1
        repeat

口パクのATLアニメーションです。
違う口パクを二つ用意したかったので用意しています。

    image 1_m1 = WhileSpeaking("b", "1_talk", "1_c_c1.png")
    image 1_m2 = WhileSpeaking("b", "1_talk", "1_c_c2.png")
    image 1_m3 = WhileSpeaking("b", "1_talk3", "1_c_c3.png")
    image 1_m4 = WhileSpeaking("b", "1_talk", "1_c_c4.png")
    image 1_m5 = WhileSpeaking("b", "1_talk", "1_c_c5.png")

   layeredimage 1:
        always "1_base"

        group a:
            attribute a1 default
            attribute a2
            attribute a3
            attribute a4
        group b:
            attribute b1 default
            attribute b2
        group c:
            attribute c0 default
            attribute c1
            attribute c2
            attribute c3
            attribute c4
            attribute c5
            attribute c6
            attribute c7
        group e:
            attribute e0 default
            attribute e1:
                "1_m1"
            attribute e2:
                "1_m2"
            attribute e3:
                "1_m3"
            attribute e4:
                "1_m4"
            attribute e5:
                "1_m5"
        group d:
            attribute d1 default
            attribute d2

アニメーションが終わった後の閉じた口パーツを指定したかったのでimageを作って
↑のようにしています。