Page 1 of 3

Character Animated Features (Eyes & Mouth)?

Posted: Wed Sep 03, 2008 4:38 am
by Nio
I would like to setup a system in Ren'Py so that I can have animated eyes and mouths.

I'm a visual person so here is a reference image that I will refer to below.

Image

My goal is to have these animations defined when I define the character and not each time I use it in the script.

To keep things efficient using small images for the eyes and mouth would be best (like in my image above). But this means that they have to be positioned over the character image. Since each character image will be a different size and in a different location the smaller animated images will need to reference where the character is. This position information would have to be setup with the character definition.

It would be nice if the mouth animation only played during the same time as the text for that character is being "typed" on the screen.

So this is what I'm thinking:

Code: Select all

#CHARACTER
    #Mii
    image mii happy = ("characters/mii/happy.png", "characters/mii/mouth.png", 20, 50, 20, 120, .1, "characters/mii/eyes.png", 20, 50, 20, 120, .1, 5)
In this make-believe example the code is:
image [name] [mood] = ("[base file name]", "[mouth file name]", [posx], [posy], [framex], [framey], [delay], "[eye file name]", [posx], [posy], [framex], [framey], [delay], [eye open delay - frame 1])

This would be used the same way it is now but with the eyes automatically looping all the time and the mouth only showing (and animating)when the text for that character is being typed on screen. It would have to know that using the character name call with text will tell it to animate the mouth. The framex and framex is what one frame (x3 in the example) is in the file so it knows where to show one frame from the file for the animation loop. The posx/y is in reference to the base character image. Delay is how much time between each frame.

The other thing to consider is what do to when the character moves. I think the easiest is to turn off the animations and hide the animated files during the transition and then have them re-evaluate the character position when it is done and continue etc.

SO I have no idea how this can be done or if it can. Either way anyone have some input?

I looked at lipflap which is close but a little bit more complex then I was hoping as you have to define the animation during each use and it has a delay for each frame/file. If I was a coding master I could probably work with that as my base for this idea. sigh...

(Disclaimer: I didn't draw that character, it is from a copyrighted games. This is just for a reference.)

Re: Character Animated Features (Eyes & Mouth)?

Posted: Wed Sep 03, 2008 4:50 am
by EvilDragon
Nio, you should get in touch with Aenakume, he/she seems very proficient in programming, as PyTom too, and Aenakume already made some great customizations of Ren'py engine (Path motions etc). Maybe he/she could help you with this, too :D

You have some great ideas and I look forward to playing your VN. Props up!

Re: Character Animated Features (Eyes & Mouth)?

Posted: Wed Sep 03, 2008 5:35 am
by Nio
Thanks. I just don't want to be a bother, but if either of them have the time it would be great. I'm sure there are many others that would like something like this anyway.

As for my own game... This will be my... yeesh, I lost count -- millionth time trying to get a game going. :P

This time I actually have a story idea, though. "crosses fingers"

Re: Character Animated Features (Eyes & Mouth)?

Posted: Wed Sep 03, 2008 7:14 am
by DaFool
Whoa, I didn't know you can just declare the dynamic images without the terms 'Animation' or 'LiveComposite', etc. I must be out of the loop...

Re: Character Animated Features (Eyes & Mouth)?

Posted: Wed Sep 03, 2008 7:15 am
by monele
You'll have to use a few image functions for this :

http://renpy.org/wiki/renpy/doc/referen ... .Composite

^ This lets you combine images AND animations

http://renpy.org/wiki/renpy/doc/referen ... /Animation

^ This lets you make an actual animation

In other words :

Code: Select all

$ anim_eyes = Animation("eyes_1.png", 0.2, "eyes_2.png", 0.2, "eyes_3.png", 0.2, ...)
image girl = im.Composite((400,540), (0,0), "girl.png", (240,160), anim_eyes)
Copy "anim_eyes" for the mouth animation if needed (is it animated?) and add it at the end of the Composite declaration.

== EDIT ==
Oops, actually, you're supposed to use LiveComposite to combine pictures and animations... my bad ^^; (otherwise, it seems to work the same)

Re: Character Animated Features (Eyes & Mouth)?

Posted: Wed Sep 03, 2008 12:34 pm
by PyTom
Hm... this is a little complicated, but not terribly so. Basically, we have to use DynamicDisplayable to switch between "text is scrolling" and "text is done" modes. We then use a LiveComposite that includes an Animation to do the lip flap in the "text is scrolling" mode. And finally, we'd want to use character callbacks to switch between the two modes.

Gimme a bit, and I'll wrap it up in a nice easy package for you.

Re: Character Animated Features (Eyes & Mouth)?

Posted: Wed Sep 03, 2008 5:09 pm
by Nio
PyTom wrote:Gimme a bit, and I'll wrap it up in a nice easy package for you.
O_O You're amazing! I hope I explained it clearly.

In my example I meant to illustrate the pos in ref to the character image, but didn't have time. I was going to put black frames around the character and the areas where the eyes and mouth files would be positioned in reference to that. IE the x0 y0 for the animated files would be based off the character image and not the game screen. I think I explained that though in the text.

Besides the mouth moving during the text, to me the other tricky part would be during transitions, IE moving or fading (out or to another mood). Like I said I think the easiest would be to just remove them, I don't think having them remain while in transition would look good. I know that during a fade you would see them even if they are fading at the same time. 50% and 50% fade would be 100% where the eyes and mouth are etc.


I and the community thank you! (yes, I speak for the community now. muhahaha. JK)

Re: Character Animated Features (Eyes & Mouth)?

Posted: Thu Sep 04, 2008 2:21 am
by PyTom

Code: Select all

init python:

    # This is set to true while a character is speaking, and False when
    # the character is done.
    speaking = False

    # This returns d if the character is speaking, and Null() if the
    # character is not. 
    def while_speaking(d, st, at):
        if speaking:
            return d, .1
        else:
            return Null(), None

    # Curried form of the above.
    curried_while_speaking = renpy.curry(while_speaking)

    # Displays d when a character is speaking, and Null otherwise.
    def WhileSpeaking(d):
        return DynamicDisplayable(curried_while_speaking(d))

    # This callback maintains the speaking variable.
    def speaker_callback(event, **kwargs):
        global speaking
        
        if event == "show":
            speaking = True
        elif event == "slow_done":
            speaking = False
        elif event == "end":
            speaking = False

    # And this is a character that uses speaking callback. By creating a
    # new character with kind=speaker, everything works out.
    speaker = Character(None, kind=adv, callback=speaker_callback)

init:

    # Create such a character.
    $ girl = Character("Girl", kind=speaker)

    # Composite things together to make a character with blinking eyes and
    # lip-flap.
    image girl = LiveComposite(
        (359, 927),
        (0, 0), "base.png",
        (101, 50), anim.Filmstrip("eye.png", (152, 121), (3, 1), 1.0),
        (170, 144), WhileSpeaking(anim.Filmstrip("kuti.png", (62, 48), (3, 1), .1)),
        )

    
        


# The game starts here.
label start:

    scene black
    show girl

    "Not speaking."

    girl "Now I'm speaking. Blah blah blah blah blah blah blah."

    "Not speaking anymore."
    
    girl "Now I'm speaking once again. Blah blah blah blah blah blah blah."
This code uses anim.Filmstrip, since the original images are filmstrips. I'd probably use Animation, which lets you change the delay between images, but that requires multiple images.

Re: Character Animated Features (Eyes & Mouth)?

Posted: Thu Sep 04, 2008 3:50 am
by Nio
This looks great. Thank you much!

BUT... as always. I have gotten an error. What else is new, eh?

So this is the character code:

Code: Select all

    image mii mad = LiveComposite(
        (411, 557),
        (0, 0), "characters/mii/mad.png",
        (52, 63), anim.Filmstrip("characters/mii/mad_eye.png", (114 , 68), (3, 1), 1.0),
        (69, 119), WhileSpeaking(anim.Filmstrip("characters/mii/mad_mouth.png", (35 , 46), (3, 1), .1)),
        )
And this is the error...
ValueError: subsurface rectangle outside surface area


And you're right, I'll probably try to use animation for the eyes so I can pause the eyes open frame for longer than the rest. I think I can add that into this... I think.

Re: Character Animated Features (Eyes & Mouth)?

Posted: Thu Sep 04, 2008 8:55 am
by delta
I would advise against using a basic Animation for blinking. It is too regular and generally just looks creepy. Use a state machine instead, it allows you to use non-deterministic intervals - http://renpy.org/wiki/renpy/doc/referen ... MAnimation (in fact, the example for this function is a character blinking, and rightly so).

Re: Character Animated Features (Eyes & Mouth)?

Posted: Thu Sep 04, 2008 10:12 am
by monele
delta : ever seen Phoenix Wright eye blinking? If so, did you think it was creepy? (because it was repeated and I thought it looked good...)

Re: Character Animated Features (Eyes & Mouth)?

Posted: Thu Sep 04, 2008 10:22 am
by Jake
monele wrote:delta : ever seen Phoenix Wright eye blinking? If so, did you think it was creepy?
I think, generally, it looks creepy if the pattern is too short. And that can mean either too short a time between blinks, or too short a sequence of blinks, but one way or another...

Re: Character Animated Features (Eyes & Mouth)?

Posted: Thu Sep 04, 2008 10:45 am
by PyTom
Nio wrote: And this is the error...
ValueError: subsurface rectangle outside surface area
This comes from getting the size of the rectangles used in anim.Filmstrip wrong. Use Animation with multiple images, and there won't be a problem.

Re: Character Animated Features (Eyes & Mouth)?

Posted: Thu Sep 04, 2008 4:50 pm
by Nio
PyTom wrote:
Nio wrote: And this is the error...
ValueError: subsurface rectangle outside surface area
This comes from getting the size of the rectangles used in anim.Filmstrip wrong. Use Animation with multiple images, and there won't be a problem.
Yeah, my images were messed up because they were resized. It works now.

I'm not sure I get the speaking and not speaking.

For example. So far the character seems to show the animated mouth during other characters. Right now I have just one character talking and the "player". The character animates during the player's text as well. Is that just a limit of this script or am I doing this wrong?

Code: Select all

mii "Hi there. I'm talking now."

player "Hi, it's nice to meet you."
If you have multiple characters on screen will they all animate with any text? In any event this is still awesome. Just need to figure this one thing with the multiple characters and it's all set.

Re: Character Animated Features (Eyes & Mouth)?

Posted: Thu Sep 04, 2008 10:43 pm
by Nio
I tested this with multiple characters on screen at once and they all will animate their mouth during any character set with kind=speaker.

Is there a way to split this up so that only the one actually speaking has the animated mouth?