Showing Layered Sprites With Different Emotions (Corrected)

A place for Ren'Py tutorials and reusable Ren'Py code.
Forum rules
Do not post questions here!

This forum is for example code you want to show other people. Ren'Py questions should be asked in the Ren'Py Questions and Announcements forum.
Post Reply
Message
Author
User avatar
Obscura
Eileen-Class Veteran
Posts: 1431
Joined: Fri Mar 09, 2012 6:58 pm
Projects: Coming Out On Top
Location: United States
Contact:

Showing Layered Sprites With Different Emotions (Corrected)

#1 Post by Obscura »

The original article on the wiki has a bit of an error that can really throw newbie programmers for a loop.
I'm just adding the missing apostrophes for future reference. :mrgreen:

Edit: 6/2/2012. Another newbie edit. If you use folders, the original cookbook suggests "/folder/image.png". There is no need for that first slash!!! Removed that first slash from the comment below.

-----------------------------------------
Showing layered sprites with different emotions

Have you ever wanted to make a layered image but you didn't want to declare separate statements for each one? Are you tired of using "show eileen happy at center with dissolve"?

Then this is for you! Welcome to the world of LiveComposite and dynamic displayables using ConditionSwitch! You'll only need to declare something like "$ Janetmood = mad" to change the emotion on her face or the pose and any number of fun things.

Code: Select all

#Put this in your init section!
init:
#This declares a conditional image with a LiveComposite inside of it
image eileen = ConditionSwitch(
            "e_face == 'happy'", LiveComposite(
                #If she's happy, call the LiveComposite
                (375, 480),
                (0, 0), "e.png",
                #This is the size of the sprite in widthxheight of pixels
                #I'm telling it not to move e.png but use the base dimensions and
                #the path to e.png. If I had it in a folder, it would be
                #"foldername/imagename.format"
                #This is probably the "base" image or body.
                (94, 66), "e_happy.png",
                #This is 94 pixels to the right and 66 pixels down, if I remember correctly
                #This is the alternate face layer, which is put on top of the stack.
                #So the order goes bottom to top when you're listing images.
                ),
            "e_face == 'sad'", LiveComposite(
                (375, 480),
                (0, 0), "e.png",
                (94, 66), "e_sad.png",
                #Don't forget your commas at the end here
                ),
            "e_face == None", "e.png")
            #If it's not set to anything, the neutral base "e.png" displays
            #Be sure to close your parentheses carefully

label start:
#This is how you call it during the game itself
show eileen
#This shows the LiveComposite "e.png" when e_face == None. We haven't changed it yet.
e "I'm neutral."
#Now we change the variable to happy.
$ e_face = "happy"
e "Now sprite is happy!"
#You can also declare ConditionSwitches in Character statements to
#change the side image.
Last edited by Obscura on Sat Jun 02, 2012 7:57 pm, edited 1 time in total.
Coming Out On Top - An Adult Gay Dating Sim
website

User avatar
Samidarenina
Regular
Posts: 137
Joined: Sun Aug 01, 2010 1:21 pm
Contact:

Re: Showing Layered Sprites With Different Emotions (Correct

#2 Post by Samidarenina »

Excuse my ignorant question, but is it possible to use transitions with this method?

User avatar
Obscura
Eileen-Class Veteran
Posts: 1431
Joined: Fri Mar 09, 2012 6:58 pm
Projects: Coming Out On Top
Location: United States
Contact:

Re: Showing Layered Sprites With Different Emotions (Correct

#3 Post by Obscura »

Samidarenina wrote:Excuse my ignorant question, but is it possible to use transitions with this method?
This is actually an excellent question. I'm looking for the answer to it myself!!!
Coming Out On Top - An Adult Gay Dating Sim
website

Endorphin
Veteran
Posts: 366
Joined: Mon Nov 22, 2010 10:52 am
Location: Germany
Contact:

Re: Showing Layered Sprites With Different Emotions (Correct

#4 Post by Endorphin »

I use a different method (composite, building the expression in-game) but what I do is to have a backup of the character and switching between them.
(Eileen and Eileen2, both are linked to the speaker (especially important if you use lip flap).)
I change the expression in 2, use a transition and switch back to 1, then again to 2, then to 1...
Not elegant but it works. =o

- R.

User avatar
Obscura
Eileen-Class Veteran
Posts: 1431
Joined: Fri Mar 09, 2012 6:58 pm
Projects: Coming Out On Top
Location: United States
Contact:

Re: Showing Layered Sprites With Different Emotions (Correct

#5 Post by Obscura »

Ryouko wrote:I use a different method (composite, building the expression in-game) but what I do is to have a backup of the character and switching between them.
(Eileen and Eileen2, both are linked to the speaker (especially important if you use lip flap).)
I change the expression in 2, use a transition and switch back to 1, then again to 2, then to 1...
Not elegant but it works. =o

- R.
Hmmm...that's an interesting and clever way to do it! It seems there must be some way of doing it so it's not so redundant.
Coming Out On Top - An Adult Gay Dating Sim
website

User avatar
Samidarenina
Regular
Posts: 137
Joined: Sun Aug 01, 2010 1:21 pm
Contact:

Re: Showing Layered Sprites With Different Emotions (Correct

#6 Post by Samidarenina »

Wouldn't it be possible to define 2 pictures as one picture? And then just use it as normal sprites?

User avatar
nyaatrap
Crawling Chaos
Posts: 1824
Joined: Mon Feb 13, 2012 5:37 am
Location: Kimashi Tower, Japan
Contact:

Re: Showing Layered Sprites With Different Emotions (Correct

#7 Post by nyaatrap »

I'm not sure but is it what you're looking for?
http://www.renpy.org/doc/html/displayab ... .Composite

User avatar
Sabotage
Regular
Posts: 27
Joined: Thu Mar 28, 2013 7:50 am
Projects: Cupcake! [WIP-40%] :: Riddled [Idea-0%]
Contact:

Re: Showing Layered Sprites With Different Emotions (Correct

#8 Post by Sabotage »

Hello! This is quite a helpful code. Sorry if the questions give hints at my noobness haha.

1. Does the init go to the main script or the separate script?
2. Is there a way to place image scripts as a separate rpy file and call them on the main script?
3. Instead of 9 mouths, 4 eyes and 5 eyebrows, would it be easier to call whole faces? I'm just concerned with the placement of the images since the graphics might look just a hairline off but still produce weird results.

Thanks!

User avatar
Obscura
Eileen-Class Veteran
Posts: 1431
Joined: Fri Mar 09, 2012 6:58 pm
Projects: Coming Out On Top
Location: United States
Contact:

Re: Showing Layered Sprites With Different Emotions (Correct

#9 Post by Obscura »

Sabotage wrote:Hello! This is quite a helpful code. Sorry if the questions give hints at my noobness haha.

1. Does the init go to the main script or the separate script?
2. Is there a way to place image scripts as a separate rpy file and call them on the main script?
3. Instead of 9 mouths, 4 eyes and 5 eyebrows, would it be easier to call whole faces? I'm just concerned with the placement of the images since the graphics might look just a hairline off but still produce weird results.

Thanks!
Someone please correct my explanations here, as I'll make my best attempts using butchered terminology and a tenuous grasp of RenPy. (Note to Sabotage--I'm actually having someone far more skilled than I am doing the harder programming tasks, thank goodness.)

1. I believe "init:" indicates wherever you want RenPy to start executing code. It can go into an .rpy file you want...that's where the computer will start following instructions (and initializing variables, etc.). Everything under init is run every time the program is run.

2. if you mean the sprite images? or the the background images? yes, you can declare all your background images in one .rpy file, and sprite images in another. Just make sure init: is at the top of those .rpy files, so RenPy knows to run all of them (initialize them) before it actually starts the code for the game. You can even put numbers after "init" to tell RenPy which order to run the .rpy files you've got. Init: will be executed before init 2:, for example.

3. Yes, people use all sorts of methods to create expressions. If all of your layers are exactly the same size (imagine a transparent layer with a single mouth that you precisely over a same-sized layer with a body), everything will already be placed exactly where it needs to be, and RenPy will stack them for you. Personally, I put a lot of time and energy combining the different eyebrows, eyes, and mouths together, though numerous artists won't use this method because they feel the entire expression should be captured in the pose of the body itself. I'm all about facial expressions though, so I currently have 70 different expressions coded for my main character to be used throughout my game. It's very much a personal preference.
Coming Out On Top - An Adult Gay Dating Sim
website

Maruska23
Newbie
Posts: 2
Joined: Sat Sep 28, 2013 4:02 am
Contact:

Re: Showing Layered Sprites With Different Emotions (Correct

#10 Post by Maruska23 »

I had a few issues with theses emotions for some while already. Thanks for clearing things up

User avatar
Arowana
Miko-Class Veteran
Posts: 531
Joined: Thu May 31, 2012 11:17 pm
Completed: a2 ~a due~
Projects: AXIOM.01, The Pirate Mermaid
Organization: Variable X, Navigame
Tumblr: navigame-media
itch: navigame
Contact:

Re: Showing Layered Sprites With Different Emotions (Correct

#11 Post by Arowana »

Samidarenina wrote:Excuse my ignorant question, but is it possible to use transitions with this method?
If anyone else is interested in this, check out Asceai's new TransitionConditionSwitch. :D
Endorphin wrote:I use a different method (composite, building the expression in-game) but what I do is to have a backup of the character and switching between them.
(Eileen and Eileen2, both are linked to the speaker (especially important if you use lip flap).)
I change the expression in 2, use a transition and switch back to 1, then again to 2, then to 1...
Not elegant but it works. =o
I used to do this as well, but TransitionConditionSwitch should be much easier. \o/
Complete: a2 ~a due~ (music, language, love)
In progress: The Pirate Mermaid (fairytale otome)
On hold: AXIOM.01 (girl detective game)

Image

M-77
Regular
Posts: 56
Joined: Tue Sep 04, 2018 7:58 am
Contact:

Re: Showing Layered Sprites With Different Emotions (Corrected)

#12 Post by M-77 »

Hello, i am new here and also to RenPy. I got this error message:
File "game/script.rpy", line 35: init statement expects a non-empty block.
init:^
I put your code in my Script.rpy at the beginning to have a "Eyes blink animation" over a faceless
base pic. All pics are 4093, 5787 for now and in the same "images\2 ir.
I am searching for the right method. Here my customized Example code:

#Put this in your init section!
init:
#This declares a conditional image with a LiveComposite inside of it
image intro004pn90 = ConditionSwitch(
"intro004pn90 == 'normal'", LiveComposite(
#If she's normal, call the LiveComposite
(4093, 5787),
(0, 0), "intro004pn91.png",
#This is the size of the sprite in widthxheight of pixels
#I'm telling it not to move intro004pn90.png but use the base dimensions and
#the path to intro004pn90.png. If I had it in a folder, it would be
#"foldername/imagename.format"
#This is probably the "base" image or body.
(0, 0), "intro004pn91.png",
#This is 0 pixels to the right and 0 pixels down, if I remember correctly
#This is the alternate face layer, which is put on top of the stack.
#So the order goes bottom to top when you're listing images.
),
"intro004pn90 == 'blink1'", LiveComposite(
(4093, 5787),
(0, 0), "intro004pn90.png",
(4093, 5787), "intro004pn92.png",
(4093, 5787),
(0, 0), "intro004pn90.png",
(4093, 5787), "intro004pn93.png",
#Don't forget your commas at the end here
),
"intro004pn90 == None", "intro004pn91.png")
#If it's not set to anything, the neutral base "intro004pn91.png" displays
#Be sure to close your parentheses carefully

# The game starts here.
label start:
#This is how you call it during the game itself
show intro004pn90 normal
#This shows the LiveComposite "intro004pn90.png" when intro004pn90 == None. We haven't

changed it yet.
e "I'm neutral."
#Now we change the variable to happy.
$ intro004pn90 = "normal"
e "Now sprite is normal!"
#You can also declare ConditionSwitches in Character statements to
#change the side image.

It is meant to let a Character blink once halfway while it is zoomed in, from big (overscreen) to small
(fit in screen size). Zoom is done, but i dont get it blinking without lag while displaying it as simple
pic´s with "Show" command and not composite before. I used the whole big 4093, 5787 pictures for
this. I want later also a talking Mouth animation for an intro and little bit random blinking Eyes while text box is showed.
Who can help? Someone have a code that i can tryout?

Post Reply

Who is online

Users browsing this forum: No registered users