Page 1 of 1

Animated lips and eye blink help!

Posted: Sat Jun 16, 2018 8:26 am
by gamajorbatistan
Been failing at implementing this for quite a while now and finally figured I should probably just ask for help. My impression is that while a little bit complicated, once the process of implementing this is figured out it can be pretty much replicated for any amount of characters and assets so I'm hoping I can achieve this without losing my mind. Or what's left of it.

A lot of googling got me some hints but I was never quite sure what I was doing wrong for it not to work. Some posts also go back to 2011 and I imagine since then the code has developed and some bits may not even work anymore.

The problem is also that I'd like randomly timed blinking to always occur, however lip moving should occur only during the characters text appearing.

Here's what I got so far (no animation seems to work)

Code: Select all

    init python:
        config.debug_sound = True
        speaking = False
        def randompause(min,max):
            return renpy.random.randint(min,max)
            
    image selina = "char/selina_base.png"
    image selinaeyes = "char/selina_eyes1.png"
    image selinabrows = "char/selina_eyebrows1.png"
    image selinamouth = "char/selina_mouth1.png"
    
    image selina_cold lip sync:
        "char/selina/Cold/selina_mouth2.png"    
        pause (randompause(1,5))
        "char/selina/Cold/selina_mouth3.png"    
        pause (randompause(1,5))
        "char/selina/Cold/selina_mouth1.png"    
        repeat

    image selina_blink lip sync:
        "char/selina/Cold/selina_eyes1.png"    
        pause (randompause(0.5,4.5))
        "char/selina/Cold/selina_eyes2.png"    
        pause (randompause(0.3,0.6)) 

and then when I later try to display this character:

Code: Select all

    show selina at center
    show selinabrows at center
    show selinaeyes at center
    show selinamouth at center
    with moveinright    

Any help but be tremendously appreciated! Maybe there's a working sample game with very simple code out there where one could have a look ?

Re: Animated lips and eye blink help!

Posted: Sat Jun 16, 2018 9:12 am
by gas
Sorry, but you defined selina_cold lip sync... and you don't show it...

Re: Animated lips and eye blink help!

Posted: Sat Jun 16, 2018 10:50 am
by gamajorbatistan
gas wrote: Sat Jun 16, 2018 9:12 am Sorry, but you defined selina_cold lip sync... and you don't show it...
I don't know how :(

I tried this and it gave me a buttload of errors (one related to the random integer function where i have real numbers instead of ints, but i don't know how to get it to accept real values)

Code: Select all

selina_cold lip sync

Re: Animated lips and eye blink help!

Posted: Sat Jun 16, 2018 12:31 pm
by Per K Grok
gamajorbatistan wrote: Sat Jun 16, 2018 10:50 am
gas wrote: Sat Jun 16, 2018 9:12 am Sorry, but you defined selina_cold lip sync... and you don't show it...
I don't know how :(

----
I'm also is pretty new to Ren'py and python (but have a fair amount of experience in other engines and languages) so I hope I don't botch things up to badly now :)


'selina_cold lip sync' is an animated image so you show it as any other image, using 'show'

Code: Select all

show selina_cold lip sync
You should probably show only that image of Selena to start with. That will limit possible errors to start with. One thing that could happen if you have other images of Sela visible is that your animation is playing behind that image and you can not see the animation even if it would be working.

I would also advice you to start off with having a 'pause 0.2' after each image in the animation (you don't have a pause after the third image) .

If that works you can try adding the random length pause.

If you start simple and and complexity as you go along it will be easier to pinpoint where stuff goes wrong.

Re: Animated lips and eye blink help!

Posted: Sat Jun 16, 2018 1:09 pm
by gamajorbatistan
Oh my god, sweet! I got it to work now. It's repeating nicely. No random pauses yet but, exactly like you wisely said, adding complexity is best done later.

The main problem I'd still really need help solving now is how to stop the lip animation when the characters line is finished. Is this very hard to accomplish? I'm worried about it because at some point I might have several characters talking on screen and they will have to take turns talking. This surely is a bit tricky to code, no?

Re: Animated lips and eye blink help!

Posted: Sat Jun 16, 2018 3:12 pm
by Per K Grok
gamajorbatistan wrote: Sat Jun 16, 2018 1:09 pm Oh my god, sweet! I got it to work now. It's repeating nicely. ---
Glad to hear that :)
gamajorbatistan wrote: Sat Jun 16, 2018 1:09 pm ---
The main problem I'd still really need help solving now is how to stop the lip animation when the characters line is finished. Is this very hard to accomplish?
---

Code: Select all


         show selina_cold lip sync
         s "bla bla bla...."
         hide selina_cold lip sync
         
         x "Bla bla bla ...."
         
         show selina_cold lip sync
         s "bla bla bla...."
         hide selina_cold lip sync

That should do it.
This is assuming that the animation is played on top of an image of the face that has a neutral mouth that will be seen when the mouth animation is turned of.

Yes, coding can be quit tricky :)

Re: Animated lips and eye blink help!

Posted: Sat Jun 16, 2018 6:18 pm
by gamajorbatistan
Wow, it works! Thanks so much. You have no idea how grateful I am. This turned out to be so much easier than I thought with a little bit of help and guidance. Seriously!

Now my last issue for the near foreseeable future. I'm a bit irked by the fact that when my character says something very short, like 'Hey you!' but the player for whatever reason isn't clicking to continue the dialogue, the animation keeps looping and in the players head goes 'Hey you! Hey you! Hey you! Hey you! Hey you!' obviously seeming a bit silly and breaking the immersion completely. Is there a function that limits the amount of times the animation loops?

Like maybe

Code: Select all

show selina_cold lip sync with limitloops(2)
or something like that?

Re: Animated lips and eye blink help!

Posted: Sat Jun 16, 2018 11:04 pm
by gamajorbatistan
I'm now trying to solve the issue by adding a manual switch.

So I declare the 'loopcounter' variable at the beginning of my project

like so

Code: Select all

    $ loopcounter = 0

and then I edit the lip sync to include this conditional statement, in order to control the number of loops by simply changing loopcounter immediately before executing the animation.

Code: Select all

    image selina_cold lip sync:
        "char/selina/Cold/selina_mouth2.png"    
        pause (randompause(1,5))
        "char/selina/Cold/selina_mouth3.png"    
        pause (randompause(1,5))
        "char/selina/Cold/selina_mouth1.png"  
        python:
            if loopcounter > 0:
                $ loopcounter -= 1
                repeat
            else:
                return
I am however getting this error:

Code: Select all

File "game/script.rpy", line 60: Line is indented, but the preceding ATL statement does not expect a block. Please check this line's indentation.
    if loopcounter > 0:
Anyone got any ideas?

Re: Animated lips and eye blink help!

Posted: Sun Jun 17, 2018 11:48 pm
by gamajorbatistan
desperate bump :(

Re: Animated lips and eye blink help!

Posted: Mon Jun 18, 2018 2:33 am
by kivik
Try ditching the $ at the start of that line - it turns the line into python > but you're already inside a python block, so maybe it's throwing that error as a result.

That said, I don't know if you can do python loop inside an image declaration. See what happens and come back if it doesn't work. You may need to change the way you approach this.

Re: Animated lips and eye blink help!

Posted: Mon Jun 18, 2018 12:53 pm
by Per K Grok
gamajorbatistan wrote: Sat Jun 16, 2018 11:04 pm ---

Anyone got any ideas?
One way would be to have a separate animation that you use only for short dialogue lines. It will run through the animation only once and then stop at the last frame in the animation. So you just repeat the frames as many times you need in the animation to get the length you want. The last frame will be visible until the 'hide' command is given. So make sure that is the neutral mouth.

I have here given the new animation the name 'selina_cold lip syncShort' to make it different from the old 'selina_cold lip sync'. You would still use the old one for longer lines of dialogue.

Code: Select all

image selina_cold lip syncShort:
        "char/selina/Cold/selina_mouth2.png"    
        pause (randompause(1,5))
        "char/selina/Cold/selina_mouth3.png"    
        pause (randompause(1,5))
        "char/selina/Cold/selina_mouth1.png" 
        pause (randompause(1,5))
        "char/selina/Cold/selina_mouth2.png"    
        pause (randompause(1,5))
        "char/selina/Cold/selina_mouth3.png"    
        pause (randompause(1,5))
        "char/selina/Cold/selina_mouth1.png" 


Not the most elegant solution and it will not give you the option to chose between different number of loops, but I think it will work. :)