How can I force my game to replace an image with another image whenever the speaker (name) changes?

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.
Post Reply
Message
Author
User avatar
Aureus
Regular
Posts: 95
Joined: Sun Aug 06, 2017 4:49 am
Completed: The Tavern
Projects: Tales From Windy Meadow
Organization: Moral Anxiety Studio
itch: moral-anxiety
Location: Breslau, Poland
Contact:

How can I force my game to replace an image with another image whenever the speaker (name) changes?

#1 Post by Aureus » Wed May 23, 2018 10:33 am

As far as I understand, the general Ren'Py line of thinking is this: when the game launches, load and apply all of the "image" commands, so the game won't refresh it's loading process every time they are called for through "show (...)".

Here is what I would like to do, but I don't how - especially since it contradicts the previously described line of thinking fundamentally: whenever a picture (not all of them, just the chosen ones) is called by "show (...)" statement, it should have a version A. However, once the "who" (speaker) changes to a different value (for example, another character starts speaking), the image should be replaced by version B - preferably with all the transformations applied to it during the original "show" statement, such as fade.

Here is an example how does this look like in the game when I add it manually (it looks weird on thumbnail but works when opened : P):
dimming.gif
I just don't want to do this for the thousands of lines of dialogues that I currently have so I wonder if you know how to make it occur on its own. I would really appreciate your help.
Tales From Windy Meadow - slice of life, pixel art Visual Novel set in a fantasy village.
The Tavern - dark fantasy RPG/Visual Novel hybrid - now available on Steam.

kivik
Miko-Class Veteran
Posts: 783
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: How can I force my game to replace an image with another image whenever the speaker (name) changes?

#2 Post by kivik » Wed May 23, 2018 11:25 am

Your line of thinking is logical, and it's correct to an extend, but Renpy's actually a lot smarter than that - and it redraws stuff as and when they need to be redrawn (preserving the order). I can't pretend to know every thing about it, but I know there're things like callbacks that can trigger a redraw for example.

What you want to do is actually quite doable, although I've not done the fade effect myself but it should be doable with ATL. In fact the method I'm sharing is what someone else taught me from before:

First add this variable define to your script: https://www.renpy.org/doc/html/config.h ... _attribute

Code: Select all

define config.speaking_attribute = "speaking" # you can call it whatever you want though, "speaker", "speaking_char", point is to give it something
As the documentation explains:
If not None, this should be a string giving the name of an image attribute. The image attribute is added to the image when the character is speaking, and removed when the character stops.
It's not explained in too much details here, but basically, your speaking character should already have an image name associated to it:

Code: Select all

image eileen = "eileen.png"
e = Character("Eileen", image="eileen")
What that config variable does is, when e (eileen) speaks, it'll check to see if the associated image is showing (eileen), and if so it'll show the image with the speaking attribute instead (eileen speaking).

So you'll need to add a new image to your character(s):

Code: Select all

image eileen = "eileen.png"
image eileen speaking = "eileen-speaking.png"
e = Character("Eileen", image="eileen")

That achieves the initial goal of showing a different image, the next step is how do we make non-speaking characters darker? First of all, we need to consider this: we're not actually doing anything special with non-speaking characters, we're declaring a new image for speaking characters. Therefore we actually need to darken the default characters and make the speaking character image the brighter version.

Second thing is, whether you want to make your own darker sprites or use Renpy's transforms to do it for you.

I've gotten help to get Renpy to darken my non-speaking character for me, however I'm not experienced enough with the ATL to suggest how to make it fade from bright to dark - though it's definitely doable.

My code to make my non-speaking characters darker is as follows:

Code: Select all

transform darken(child,value=0.25):
    AlphaBlend(At(child, mask(value)), child, Solid("#000"), alpha=True)

image eileen:
    At("eileen.png", darken)
image eileen speaking:
    "eileen.png"
This thread does talk about darkening a sprite overtime, though I haven't got time to test it out myself:

viewtopic.php?f=8&t=38231

Good luck!

User avatar
Aureus
Regular
Posts: 95
Joined: Sun Aug 06, 2017 4:49 am
Completed: The Tavern
Projects: Tales From Windy Meadow
Organization: Moral Anxiety Studio
itch: moral-anxiety
Location: Breslau, Poland
Contact:

Re: How can I force my game to replace an image with another image whenever the speaker (name) changes?

#3 Post by Aureus » Wed May 23, 2018 12:03 pm

Thank you for writing back, kivik! However - do you have an idea how could I use it not only for a character, but also for all the portraits this character has? Basically, some of my characters have 10+ portraits available and a simple "speaking-not speaking" pair won't work for me. : ( Or maybe the answer is already here but I just missed it, if that's the case, I apologize.
Tales From Windy Meadow - slice of life, pixel art Visual Novel set in a fantasy village.
The Tavern - dark fantasy RPG/Visual Novel hybrid - now available on Steam.

kivik
Miko-Class Veteran
Posts: 783
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: How can I force my game to replace an image with another image whenever the speaker (name) changes?

#4 Post by kivik » Wed May 23, 2018 12:10 pm

Admittedly the approach is easier for me, because I use Dynamic Images myself, so I only need a single image for each of my characters - and change their corresponding image by variables, for example:

Code: Select all

image eileen:
    At("eileen/[eileen.outfit]-[eileen.mood].png", darken)
image eileen speaking:
    "eileen/[eileen.outfit]-[eileen.mood].png"
If you can't / don't fancy using that, I'm afraid you'll have to just duplicate your portrait declarations so you have a non-speaking and speaking version for each one.

User avatar
Aureus
Regular
Posts: 95
Joined: Sun Aug 06, 2017 4:49 am
Completed: The Tavern
Projects: Tales From Windy Meadow
Organization: Moral Anxiety Studio
itch: moral-anxiety
Location: Breslau, Poland
Contact:

Re: How can I force my game to replace an image with another image whenever the speaker (name) changes?

#5 Post by Aureus » Wed May 23, 2018 12:31 pm

Thank you so much for explaining this, kivik. <3
Tales From Windy Meadow - slice of life, pixel art Visual Novel set in a fantasy village.
The Tavern - dark fantasy RPG/Visual Novel hybrid - now available on Steam.

Post Reply

Who is online

Users browsing this forum: IaMe