changing a character emotions

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
shiza
Regular
Posts: 29
Joined: Wed Jun 14, 2017 12:36 pm
Contact:

changing a character emotions

#1 Post by shiza »

let's say we have a character name bob and I want to show all the different emotions of bob.
what is the most profficent way of doing that. is it possible to link a character to a folder that contains all the images related to that character and pull from the folder using a naming convention of "angry.png" instead of having one huge folder where you will have to name everything like "bob_happy.png" "sara_happy.png"?

User avatar
DannyGMaster
Regular
Posts: 113
Joined: Fri Sep 02, 2016 11:07 am
Contact:

Re: changing a character emotions

#2 Post by DannyGMaster »

Well, yes. You can have:

Code: Select all

image bob happy = 'images/bob/bob_happy.png'
image bob angry = 'images/bob/bob_angry.png'
image sara happy = 'images/sara/sara_happy.png'
image sara angry = 'images/sara/sara_angry.png'

define bob = Character('Bob')
define sara = Character('Sara')

label start:
    show bob angry with dissolve

    bob "Sometimes I'm angry"

    show bob happy with dissolve

    bob "But most of the time I'm happy"

    show sara happy at right with dissolve

    sara "Me too!"    
The silent voice within one's heart whispers the most profound wisdom.

User avatar
Mammon
Miko-Class Veteran
Posts: 712
Joined: Sat Nov 07, 2015 3:09 pm
Completed: Pervert&Yandere, Stalker&Yandere
Projects: Roses Of The Thorn Prince
Contact:

Re: changing a character emotions

#3 Post by Mammon »

If there's a large amount of expressions, you can also make the base (everything except the expressions) a separate file and then place all the expressions without base in separate .png files. Saves on the amount of MBs you'll have. But that shouldn't be necessary until there's a large amount (let's say, +50) of expressions. As long as you keep the image size the same for the expressions and the base, you won't have to juggle with positions either, the expressions will be on the right spot.
ImageImageImage

Want some CC sprites?

User avatar
Scribbles
Miko-Class Veteran
Posts: 636
Joined: Wed Sep 21, 2016 4:15 pm
Completed: Pinewood Island, As We Know It
Projects: In Blood
Organization: Jaime Scribbles Games
Deviantart: breakfastdoodles
itch: scribbles
Location: Ohio
Contact:

Re: changing a character emotions

#4 Post by Scribbles »

LiveComposite with ConditionSwitch's work really nicely, kind of what Mammon was saying. I use it for any number of expressions because it just seems... better? though that might just be a personal preference. Here is an example:

Code: Select all

image bob = LiveComposite((0,0),
     (0,0), "bob_base.png",
     (0,0), ConditionSwitch(
          "bob_expression == 'happy'", "bob_happy.png",
          "bob_expression == 'sad'", bob_sad.png",
          ),
     )
the code probably isn't that great, but hopefully you get the idea :)
Image - Image -Image

shiza
Regular
Posts: 29
Joined: Wed Jun 14, 2017 12:36 pm
Contact:

Re: changing a character emotions

#5 Post by shiza »

Mammon wrote:If there's a large amount of expressions, you can also make the base (everything except the expressions) a separate file and then place all the expressions without base in separate .png files. Saves on the amount of MBs you'll have. But that shouldn't be necessary until there's a large amount (let's say, +50) of expressions. As long as you keep the image size the same for the expressions and the base, you won't have to juggle with positions either, the expressions will be on the right spot.
ok I'm a bit confused by your answer. all of my expressions are in a individual png file. I learn you can use paths to an image which is nice but I want to know if there's a better way to put images in the game besides making 50+ image statements in the a game script file.

shiza
Regular
Posts: 29
Joined: Wed Jun 14, 2017 12:36 pm
Contact:

Re: changing a character emotions

#6 Post by shiza »

Scribbles wrote:LiveComposite with ConditionSwitch's work really nicely, kind of what Mammon was saying. I use it for any number of expressions because it just seems... better? though that might just be a personal preference. Here is an example:

Code: Select all

image bob = LiveComposite((0,0),
     (0,0), "bob_base.png",
     (0,0), ConditionSwitch(
          "bob_expression == 'happy'", "bob_happy.png",
          "bob_expression == 'sad'", bob_sad.png",
          ),
     )
the code probably isn't that great, but hopefully you get the idea :)
so in script file I can say

show bob happy

and it will show bob with the version bob_happy?

User avatar
DannyGMaster
Regular
Posts: 113
Joined: Fri Sep 02, 2016 11:07 am
Contact:

Re: changing a character emotions

#7 Post by DannyGMaster »

shiza wrote:
Scribbles wrote:LiveComposite with ConditionSwitch's work really nicely, kind of what Mammon was saying. I use it for any number of expressions because it just seems... better? though that might just be a personal preference. Here is an example:

Code: Select all

image bob = LiveComposite((0,0),
     (0,0), "bob_base.png",
     (0,0), ConditionSwitch(
          "bob_expression == 'happy'", "bob_happy.png",
          "bob_expression == 'sad'", bob_sad.png",
          ),
     )
the code probably isn't that great, but hopefully you get the idea :)
so in script file I can say

show bob happy

and it will show bob with the version bob_happy?
Not exactly. Instead of showing a new image, you would need only to change the value of the variable bob_expression and the image bob will change automatically.
The silent voice within one's heart whispers the most profound wisdom.

shiza
Regular
Posts: 29
Joined: Wed Jun 14, 2017 12:36 pm
Contact:

Re: changing a character emotions

#8 Post by shiza »

DannyGMaster wrote:
shiza wrote:
Scribbles wrote:LiveComposite with ConditionSwitch's work really nicely, kind of what Mammon was saying. I use it for any number of expressions because it just seems... better? though that might just be a personal preference. Here is an example:

Code: Select all

image bob = LiveComposite((0,0),
     (0,0), "bob_base.png",
     (0,0), ConditionSwitch(
          "bob_expression == 'happy'", "bob_happy.png",
          "bob_expression == 'sad'", bob_sad.png",
          ),
     )
the code probably isn't that great, but hopefully you get the idea :)
so in script file I can say

show bob happy

and it will show bob with the version bob_happy?
Not exactly. Instead of showing a new image, you would need only to change the value of the variable bob_expression and the image bob will change automatically.
ok so how do you declare bob_expression? because I feel like it's not a simple variable declaration.
Also what would the code look like when you want to change from happy.png to sad.png?

User avatar
Mammon
Miko-Class Veteran
Posts: 712
Joined: Sat Nov 07, 2015 3:09 pm
Completed: Pervert&Yandere, Stalker&Yandere
Projects: Roses Of The Thorn Prince
Contact:

Re: changing a character emotions

#9 Post by Mammon »

shiza wrote:all of my expressions are in a individual png file. I learn you can use paths to an image which is nice but I want to know if there's a better way to put images in the game besides making 50+ image statements in the a game script file.
A .png file doesn't have layers, so that will be only one expression. Take my avatar, that's one image. However, in my game the base (the face) and the expressions (eyes, eyebrows and mouth) are separate images of one another. So, because the face isn't in the expressions .png, you save those bytes. If there were to be 50+ expressions, that will actually matter a lot in terms of your game file size.

Look at my avatar again, there is also a shirt and a hand, both separate layers. Plus, the eyebrows, eyes and mouths are all separate images as well. That might seem like more images, but if they are in separate files, they do decrease the amount of images you'll need to make. Let's say you've got 12 images without the hand. Now you add the hand, those would have to be 12 more images if you were to use complete images. If you just add a .png of just a hand, that's just one more image.

I don't know if that clears things up, if you already knew it, or if this wasn't even what you were asking about, but whatever. Hope it helps.
ImageImageImage

Want some CC sprites?

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: changing a character emotions

#10 Post by trooper6 »

shiza wrote:let's say we have a character name bob and I want to show all the different emotions of bob.
what is the most profficent way of doing that. is it possible to link a character to a folder that contains all the images related to that character and pull from the folder using a naming convention of "angry.png" instead of having one huge folder where you will have to name everything like "bob_happy.png" "sara_happy.png"?
shiza wrote:ok I'm a bit confused by your answer. all of my expressions are in a individual png file. I learn you can use paths to an image which is nice but I want to know if there's a better way to put images in the game besides making 50+ image statements in the a game script file.
There are a lot of answers people have given you. I'm going to give you the most simple one based on what it seems your files are like (complete images of the sprites, but with different emotions). In other words, One for angry bob, one for sad bob, etc.

For that, you don't need complicated dynamic images or ConditionSwitches. I'm using those for my game, but that is because I have incomplete sprites that I then layer eyes and mouths and shirts on top of depending on what's going on. Since you aren't doing that, you don't need any of that.

So let's start with your question of not wanting to make 50+ image statements in the game script file. You don't have to. Renpy automatically defines the images for you as long as you follow the right naming convention of your files.

You want all your image files in the images folder. If you want to have subfolders in there you can. You can have a bob subfolder and a sarah subfolder. You can have whatever subfolder you want if it makes it more comfortable for you. Renpy will ignore these subfolders, but if it is better for your sense of organization, go for it. What is important is that your files are named "bob angry.png" or "sarah angry.png"
You do this and renpy will strip the file of the extension and create a definition of each file in your images folders and subfolders that way. This is detailed in the documentation here:
https://www.renpy.org/doc/html/displayi ... -directory

So, if all your files are named properly, then you don't need to define them, Ren'py does it for you.

Next up. Showing emotions. You want to create characters for your people and then connect an image tag to that character that matches your image names. Note: you should always avoid naming two different things the same name. So I wouldn't have a character named bob and an image named bob. I'd name the character b and the images bob.

Once that is done, you show the image once for the scene and then you can change emotions as part of the say statement.

It looks like this.

Let's assume you have 6 images, three bob and three sarah. And they are in bob and sarah subfolders:
images/bob/bob neutral.png
images/bob/bob angry.png
images/bob/bob sad.png
images/sarah/sarah neutral.png
images/sarah/sarah angry.png
images/sarah/sarah sad.png

You don't have to define them, you just do this:

Code: Select all

define b = Character("Bob", image="bob")
define s = Character("Sarah", image="sarah")

label start:
    "You game starts here."
    show bob neutral at left
    show sarah neutral at right
    b "Sarah, nice to see you, finally."
    s angry "What is that supposed to mean?"
    b angry "What do you think it is supposed to mean?! I waited 14 hours for you do show up at the bridge!"
    s neutral "Bridge? What are you talking about?"
    b "I texted you to meet at the bridge yesterday."
    s sad "My phone was stolen over the weekend, I never got your text."
    b sad "Oh! I'm so sorry."
    return
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

shiza
Regular
Posts: 29
Joined: Wed Jun 14, 2017 12:36 pm
Contact:

Re: changing a character emotions

#11 Post by shiza »

Mammon wrote:
shiza wrote:all of my expressions are in a individual png file. I learn you can use paths to an image which is nice but I want to know if there's a better way to put images in the game besides making 50+ image statements in the a game script file.
A .png file doesn't have layers, so that will be only one expression. Take my avatar, that's one image. However, in my game the base (the face) and the expressions (eyes, eyebrows and mouth) are separate images of one another. So, because the face isn't in the expressions .png, you save those bytes. If there were to be 50+ expressions, that will actually matter a lot in terms of your game file size.

Look at my avatar again, there is also a shirt and a hand, both separate layers. Plus, the eyebrows, eyes and mouths are all separate images as well. That might seem like more images, but if they are in separate files, they do decrease the amount of images you'll need to make. Let's say you've got 12 images without the hand. Now you add the hand, those would have to be 12 more images if you were to use complete images. If you just add a .png of just a hand, that's just one more image.

I don't know if that clears things up, if you already knew it, or if this wasn't even what you were asking about, but whatever. Hope it helps.
yes it makes a lot of sense and it is something I would like to implement into the game. So when I'm in photoshop I create a naked model with a pose. then create layers showing different expressions/ wearing clothes using the model as "physical" reference. Originally I was thinking about making a still image of all the possible outcomes but you're right that would take up a lot of space. So instead when I'm done drawing, I export a single layer and save it to a library like bob_faces or bob_clothes and manipulate them in game. correct?

If so then is there a code example that shows me a complete implementation of this method?

shiza
Regular
Posts: 29
Joined: Wed Jun 14, 2017 12:36 pm
Contact:

Re: changing a character emotions

#12 Post by shiza »

trooper6 wrote:
shiza wrote:let's say we have a character name bob and I want to show all the different emotions of bob.
what is the most profficent way of doing that. is it possible to link a character to a folder that contains all the images related to that character and pull from the folder using a naming convention of "angry.png" instead of having one huge folder where you will have to name everything like "bob_happy.png" "sara_happy.png"?
shiza wrote:ok I'm a bit confused by your answer. all of my expressions are in a individual png file. I learn you can use paths to an image which is nice but I want to know if there's a better way to put images in the game besides making 50+ image statements in the a game script file.
There are a lot of answers people have given you. I'm going to give you the most simple one based on what it seems your files are like (complete images of the sprites, but with different emotions). In other words, One for angry bob, one for sad bob, etc.

For that, you don't need complicated dynamic images or ConditionSwitches. I'm using those for my game, but that is because I have incomplete sprites that I then layer eyes and mouths and shirts on top of depending on what's going on. Since you aren't doing that, you don't need any of that.

So let's start with your question of not wanting to make 50+ image statements in the game script file. You don't have to. Renpy automatically defines the images for you as long as you follow the right naming convention of your files.

You want all your image files in the images folder. If you want to have subfolders in there you can. You can have a bob subfolder and a sarah subfolder. You can have whatever subfolder you want if it makes it more comfortable for you. Renpy will ignore these subfolders, but if it is better for your sense of organization, go for it. What is important is that your files are named "bob angry.png" or "sarah angry.png"
You do this and renpy will strip the file of the extension and create a definition of each file in your images folders and subfolders that way. This is detailed in the documentation here:
https://www.renpy.org/doc/html/displayi ... -directory

So, if all your files are named properly, then you don't need to define them, Ren'py does it for you.

Next up. Showing emotions. You want to create characters for your people and then connect an image tag to that character that matches your image names. Note: you should always avoid naming two different things the same name. So I wouldn't have a character named bob and an image named bob. I'd name the character b and the images bob.

Once that is done, you show the image once for the scene and then you can change emotions as part of the say statement.

It looks like this.

Let's assume you have 6 images, three bob and three sarah. And they are in bob and sarah subfolders:
images/bob/bob neutral.png
images/bob/bob angry.png
images/bob/bob sad.png
images/sarah/sarah neutral.png
images/sarah/sarah angry.png
images/sarah/sarah sad.png

You don't have to define them, you just do this:

Code: Select all

define b = Character("Bob", image="bob")
define s = Character("Sarah", image="sarah")

label start:
    "You game starts here."
    show bob neutral at left
    show sarah neutral at right
    b "Sarah, nice to see you, finally."
    s angry "What is that supposed to mean?"
    b angry "What do you think it is supposed to mean?! I waited 14 hours for you do show up at the bridge!"
    s neutral "Bridge? What are you talking about?"
    b "I texted you to meet at the bridge yesterday."
    s sad "My phone was stolen over the weekend, I never got your text."
    b sad "Oh! I'm so sorry."
    return
Ok that's make sense. I have a question so I can completely understand this method.

So lets assume we named a image "sarah_neutral.png" or "neautral.png" instead of "sarah neutral.png". will the show statement "show sarah neutral at right" be the same?

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: changing a character emotions

#13 Post by trooper6 »

shiza wrote: So lets assume we named a image "sarah_neutral.png" or "neautral.png" instead of "sarah neutral.png". will the show statement "show sarah neutral at right" be the same?
If you name the file "sarah_neutral.png" or "neutral.png" renpy will not automatically define the images for you and you will have to define them all manually.

You have two options:
Option 1) You name your files however you want and then manually define them. "sarah_neutral.png" or "neutral.png"
Option 2) You name your files in a way that is compatible with automatic definition and Renpy does it for you. "sarah neutral.png"

Your choice.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2384
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: changing a character emotions

#14 Post by Ocelot »

< < insert Rick Cook quote here > >

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: changing a character emotions

#15 Post by trooper6 »

Ocelot wrote:Option 3) Add _ to the list of separators for automatic images
This is true. But I wanted to keep it super simple for the OP since it seems they are still learning the very basics of Ren'Py.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

Post Reply

Who is online

Users browsing this forum: No registered users