Character Animated Features (Eyes & Mouth)?

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Message
Author
User avatar
PyTom
Ren'Py Creator
Posts: 15316
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Character Animated Features (Eyes & Mouth)?

#16 Post by PyTom » Fri Sep 05, 2008 12:35 am

Updated code. Note that the character definition no longer uses kind, but instead uses callback=talker("name"). The first parameter to WhileSpeaking should match the name given as a parameter to talker... that's how we tell them apart.

Code: Select all

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 d if the character is speaking, and Null() if the
    # character is not. 
    def while_speaking(name, d, st, at):
        if speaking == name:
            return d, .1
        else:
            return Null(), None

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

    # Displays d when the named character is speaking, and Null otherwise.
    def WhileSpeaking(name, d):
        return DynamicDisplayable(curried_while_speaking(name, 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)
            
init:

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

    # 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("girl", 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."
BTW, if some of our coders want to take a look at this and ask questions about how it works, please do. I think it's an interesting example of how one can add features to Ren'Py without having to change the core engine at all.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
"Silly and fun things are important." - Elon Musk
Software > Drama • https://www.patreon.com/renpytom

User avatar
Nio
Regular
Posts: 160
Joined: Mon Jan 03, 2005 4:37 am
Projects: ??????
Location: In his own little world.
Contact:

Re: Character Animated Features (Eyes & Mouth)?

#17 Post by Nio » Fri Sep 05, 2008 12:48 am

*cheers* That did the trick! I hope this is helpfull to others too.

User avatar
chronoluminaire
Eileen-Class Veteran
Posts: 1153
Joined: Mon Jul 07, 2003 4:57 pm
Completed: Elven Relations, Cloud Fairy, When I Rule The World
Tumblr: alextfish
Skype: alextfish
Location: Cambridge, UK
Contact:

Re: Character Animated Features (Eyes & Mouth)?

#18 Post by chronoluminaire » Mon Sep 08, 2008 10:53 am

Seems to me this is a prime example of code that we agreed a couple of months back it'd be good to preserve on the cookbook. So I pasted it in there.
I released 3 VNs, many moons ago: Elven Relations (IntRenAiMo 2007), When I Rule The World (NaNoRenO 2005), and Cloud Fairy (the Cute Light & Fluffy Project, 2009).
More recently I designed the board game Steam Works (published in 2015), available from a local gaming store near you!

User avatar
Maruta
Regular
Posts: 31
Joined: Wed Jun 25, 2008 12:02 pm
Location: Aivtal
Contact:

Re: Character Animated Features (Eyes & Mouth)?

#19 Post by Maruta » Thu Oct 30, 2008 9:35 am

*posting in a legendary thread*

Ah, this looks useful, but I have a silly, no, idiotic question.

Code: Select all

image girl = LiveComposite(
        (359, 927),
        (0, 0), "base.png",
        (101, 50), anim.Filmstrip("eye.png", (152, 121), (3, 1), 1.0),
        (170, 144), WhileSpeaking("girl", anim.Filmstrip("kuti.png", (62, 48), (3, 1), .1)),
here, the numerical values..what exactly do they stand for? I know what they mean, but which is what? Like, which is the size of the image or which is the location of it? And how do you get these D:?

User avatar
Jo'ogn
Veteran
Posts: 398
Joined: Sat Jul 12, 2008 1:31 pm
Projects: Kassiopeia [iVN]
Location: Deutschland
Contact:

Re: Character Animated Features (Eyes & Mouth)?

#20 Post by Jo'ogn » Fri Oct 31, 2008 12:18 pm

The answers are somwhere in here. I myself needed to read it like 4 times until I got the "odd" and "even" parameter concenpt PyTom uses...
http://www.renpy.org/wiki/LiveComposite
http://www.renpy.org/wiki/anim.Filmstrip

po_oq *gambatte*

If I got that correctly: First tuple is size. The following are a pairs of tuples of position and a displayables.
Audio Plays: [original] The White Feathers Directive - [Star Wars] Through Flame and Shadow
Ren'Py: Kassiopeia [very interactive VN] work in progress - looking for proof reader english

Foxys
Newbie
Posts: 11
Joined: Wed Sep 16, 2009 3:36 am
Projects: YCD... en proseso :3
Contact:

Re: Character Animated Features (Eyes & Mouth)?

#21 Post by Foxys » Sun Sep 20, 2009 5:28 am

I copy and paste this code and chage de name of the .mpg.... and compile it fine... but when I play the game jump this exepcion....

Code: Select all

While running game code:
 - script at line 7 of C:\Documents and Settings\Administrador\Mis documentos\Downloads\SIMDATE\YCD/game/script.rpy

-- Full Traceback ------------------------------------------------------------

  File "C:\Documents and Settings\Administrador\Mis documentos\Downloads\SIMDATE\renpy-6.9.3\renpy\bootstrap.py", line 260, in bootstrap
  File "C:\Documents and Settings\Administrador\Mis documentos\Downloads\SIMDATE\renpy-6.9.3\renpy\main.py", line 308, in main
  File "C:\Documents and Settings\Administrador\Mis documentos\Downloads\SIMDATE\renpy-6.9.3\renpy\main.py", line 92, in run
  File "C:\Documents and Settings\Administrador\Mis documentos\Downloads\SIMDATE\renpy-6.9.3\renpy\execution.py", line 230, in run
  File "C:\Documents and Settings\Administrador\Mis documentos\Downloads\SIMDATE\renpy-6.9.3\renpy\ast.py", line 341, in execute
  File "C:\Documents and Settings\Administrador\Mis documentos\Downloads\SIMDATE\renpy-6.9.3\renpy\exports.py", line 507, in say
  File "C:\Documents and Settings\Administrador\Mis documentos\Downloads\SIMDATE\renpy-6.9.3\renpy\character.py", line 546, in __call__
  File "C:\Documents and Settings\Administrador\Mis documentos\Downloads\SIMDATE\renpy-6.9.3\renpy\character.py", line 505, in do_display
  File "C:\Documents and Settings\Administrador\Mis documentos\Downloads\SIMDATE\renpy-6.9.3\renpy\character.py", line 320, in display_say
  File "C:\Documents and Settings\Administrador\Mis documentos\Downloads\SIMDATE\renpy-6.9.3\renpy\ui.py", line 69, in interact
  File "C:\Documents and Settings\Administrador\Mis documentos\Downloads\SIMDATE\renpy-6.9.3\renpy\display\core.py", line 1364, in interact
  File "C:\Documents and Settings\Administrador\Mis documentos\Downloads\SIMDATE\renpy-6.9.3\renpy\display\core.py", line 1509, in interact_core
  File "C:\Documents and Settings\Administrador\Mis documentos\Downloads\SIMDATE\renpy-6.9.3\renpy\display\core.py", line 241, in predict
  File "C:\Documents and Settings\Administrador\Mis documentos\Downloads\SIMDATE\renpy-6.9.3\renpy\display\core.py", line 215, in visit_all
  File "C:\Documents and Settings\Administrador\Mis documentos\Downloads\SIMDATE\renpy-6.9.3\renpy\display\core.py", line 241, in <lambda>
  File "C:\Documents and Settings\Administrador\Mis documentos\Downloads\SIMDATE\renpy-6.9.3\renpy\display\im.py", line 429, in predict_one
  File "C:\Documents and Settings\Administrador\Mis documentos\Downloads\SIMDATE\renpy-6.9.3\renpy\display\im.py", line 188, in get
  File "C:\Documents and Settings\Administrador\Mis documentos\Downloads\SIMDATE\renpy-6.9.3\renpy\display\im.py", line 944, in load
ValueError: subsurface rectangle outside surface area
the olny thing I changed is this:

Code: Select all

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

User avatar
PyTom
Ren'Py Creator
Posts: 15316
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Character Animated Features (Eyes & Mouth)?

#22 Post by PyTom » Sun Sep 20, 2009 12:26 pm

Probably, this is because the size of the filmstrip is outside the area of your image.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
"Silly and fun things are important." - Elon Musk
Software > Drama • https://www.patreon.com/renpytom

Foxys
Newbie
Posts: 11
Joined: Wed Sep 16, 2009 3:36 am
Projects: YCD... en proseso :3
Contact:

Re: Character Animated Features (Eyes & Mouth)?

#23 Post by Foxys » Sun Sep 20, 2009 9:12 pm

... I feel ... stupid....

thanx... :oops:

User avatar
kuzai
Regular
Posts: 85
Joined: Sat May 12, 2012 8:15 pm
Projects: Custom Lover, PuppyShipping DWH, Yu-Gi-Oh!: Chat
Location: Canada
Contact:

Re: Character Animated Features (Eyes & Mouth)?

#24 Post by kuzai » Fri Nov 02, 2012 12:30 am

Hey I have tried using this animation thing here but ummmm well here is the code

Code: Select all

# You can place the script of your game in this file.

# Declare images below this line, using the image statement.
image toko = "base.png"
image eye_closed = "eye_closed.png"
image eye_open = "eye_open.png"
image mouth_closed = "mouth_closed.png"
image mouth_speak1 = "mouth_speak1.png"
image mouth_speak2 = "mouth_speak2.png"

# Declare characters used by this game.
define toko = Character('Toko', color="#c8ffc8")


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
        else:
            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)
           
init:
  
    # Create such a character.
    $ toko= Character("toko", callback=speaker("toko"))
  
    # Composite things together to make a character with blinking eyes and
    # lip-flap.
    image toko = LiveComposite(
        (359, 927),
        (0, 0), "Base.png",
        (101, 50), Animation("eye_open.png", 4.5, "eye_closed.png", .25) ,
        (170, 144), WhileSpeaking("toko", Animation("mouth_speak1.png", .2,
        "mouth_speak2.png", .2), "mouth_closed.png"),
        )
  
# The game starts here.
label start:
  
    scene black
    show toko
  
    "Not speaking."
  
    toko "Now I'm speaking. Blah blah blah blah blah blah blah."
  
    "Not speaking any more."
   
    toko "Now I'm speaking once again. Blah blah blah blah blah blah blah."
but all I get is this

Image

Am I doing something wrong?
I forgive and forget. Because I have a good heart and terrible memory

User avatar
Kia
Miko-Class Veteran
Posts: 717
Joined: Fri Aug 01, 2014 7:49 am
Deviantart: KiaAzad
Skype: KiaAzad
Contact:

Re: Character Animated Features (Eyes & Mouth)?

#25 Post by Kia » Tue Sep 30, 2014 8:21 am

I managed to understand what this awesome code does and tried to use it simple (with simple animation) but the animations freeze on the first image and wont flap/blink. perhaps something I'm doing wrong :mrgreen: can somebody check the problem please?

Code: Select all

init -100 python:    
    #LipFlap
    speaking = None

    def while_speaking(name, d, st, at):
        if speaking == name:
            return d, .1
        else:
            return Null(), None

    curried_while_speaking = renpy.curry(while_speaking)

    def WhileSpeaking(name, d):
        return DynamicDisplayable(curried_while_speaking(name, d))

    def speaker_callback(name, event, **kwargs):
        global speaking
        
        if event == "show":
            speaking = name
        elif event == "slow_done":
            speaking = None
        elif event == "end":
            speaking = None

    speaker = renpy.curry(speaker_callback)
    #----LipFlap
    
image eyes:
    "eye.png"
    time 2.0
    "blink.png"
    time 2.0
    repeat
image mouth:
    "mouth.png"
    time 0.5
    "mouth1.png"
    time 0.5
    "mouth2.png"
    time 0.5
    repeat
    
init:

    $ girl = Character("Girl", callback=speaker("girl"))

    image girl = LiveComposite((558, 504),
        (0, 0), "base.png",
        (0, 0), "eyes",
        (0, 0), WhileSpeaking("girl", "mouth")
        )

User avatar
renoa-heartilly
Regular
Posts: 115
Joined: Sat Jul 17, 2010 2:37 am
Completed: مقهى الضائعون, Arabic Translations for Ren'py, Pretty Please
Projects: حور, BB project, dentist drama
Organization: stanza studio (creative circle)
Contact:

Re: Character Animated Features (Eyes & Mouth)?

#26 Post by renoa-heartilly » Tue Sep 30, 2014 1:55 pm

not sure if you should be reviving this thread, but i'd go to options.rpy to make sure the characters per second (config.default_text_cps = 10) is any number higher than 0 + remember to clear your persistents from the renpy launcher front page because the cps is something that is remembered by renpy by default ^^

User avatar
Alex
Lemma-Class Veteran
Posts: 2070
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Character Animated Features (Eyes & Mouth)?

#27 Post by Alex » Tue Sep 30, 2014 2:58 pm

Also, try to rename one of the character or the image (they both named "girl"), and WhileSpeaking also requires the image to show when talking is done.

Edit: oops, shouldn't post so quick...
The problem is time statement - http://www.renpy.org/doc/html/atl.html#time-statement
should be

Code: Select all

image eyes:
    "eye.png"
    2.0
    "blink.png"
    2.0
    repeat

User avatar
Kia
Miko-Class Veteran
Posts: 717
Joined: Fri Aug 01, 2014 7:49 am
Deviantart: KiaAzad
Skype: KiaAzad
Contact:

Re: Character Animated Features (Eyes & Mouth)?

#28 Post by Kia » Tue Sep 30, 2014 3:16 pm

Alex wrote:The problem is time statement
exactly ^_^
I wounder if "time" is removed or something in the new screen language

User avatar
Alex
Lemma-Class Veteran
Posts: 2070
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Character Animated Features (Eyes & Mouth)?

#29 Post by Alex » Tue Sep 30, 2014 3:25 pm

It's not removed, but (as documentation said) the values must increase from one to another.

Post Reply

Who is online

Users browsing this forum: Imperf3kt, isobellesophia