(Basic Question) Replacing character portraits when the speaker 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
PoppySun
Newbie
Posts: 4
Joined: Mon Jun 04, 2018 7:39 pm
Projects: (Secret): Project Violet
Contact:

(Basic Question) Replacing character portraits when the speaker changes?

#1 Post by PoppySun » Fri Nov 02, 2018 9:04 pm

Hi, I'm starting out with Ren'Py, and have read through the entire in game tutorial, and am about halfway through the documentation. I have what I think is a simple question:
What is the best way to write the code for a scene where one character portrait is shown at a time, on the right side, and when the speaker changes, the portrait changes? Most of the documentation and search results I've seen seems to be for replacing images for one character at a time, or having multiple characters on the screen at once.
At first, I ended up with the character portraits stacking on top of each other on the right side, until I figured out how to write this:

Code: Select all

define a = Character("Aria")
define gp = Character("Grandpa")
define f = Character("Fish")

image GP = "GP.png"
image Aria = "Aria.png"
image Fish = "Fish.png"

label start
    scene bg sea

    show GP at right
    
    gp "Ah, look at this!"

    hide GP
    
    show Aria at right
    
    a "(Happy) What a beautiful fish! <3 "
    
    hide Aria
    show GP at right
    
    gp "I hope he tastes as good as he looks."
    
    hide GP
    show Fish at right
    
    f "Wait! Don't eat me!"
    
    hide Fish
    show Aria at right
    
    a "(Surprised) It talks!"
return
My question is, is there a more optimal way to change the portrait every time the speaker changes? Or should I do a hide-show each time. Thank you!

User avatar
IrinaLazareva
Veteran
Posts: 399
Joined: Wed Jun 08, 2016 1:49 pm
Projects: Legacy
Organization: SunShI
Location: St.Petersburg, Russia
Contact:

Re: (Basic Question) Replacing character portraits when the speaker changes?

#2 Post by IrinaLazareva » Sat Nov 03, 2018 4:09 am

well, as one of possible decisions:

1) change the say() screen in screens.rpy:

Code: Select all

## https://www.renpy.org/doc/html/screen_special.html#say

screen say(who, what):
    style_prefix "say"
    window:
        id "window"
        if who is not None:
            window:
                id "namebox"
                style "namebox"
                text who id "who"
        text what id "what"
    ## If there's a side image, display it above the text. Do not display on the
    ## phone variant - there's no room.
    if not renpy.variant("small"):
        add SideImage() xalign 1.0 yalign 1.0              <<<<<< this line
2) and then

Code: Select all

define a = Character("Aria", image='Aria')
define gp = Character("Grandpa", image='GP')
define f = Character("Fish", image='Fish')
image side GP = "GP.png"
image side Aria = "Aria.png"
image side Fish = "Fish.png"

label start:
    scene bg sea
    
    gp "Ah, look at this!"
    
    a "(Happy) What a beautiful fish! <3 "
    
    gp "I hope he tastes as good as he looks."
    
    f "Wait! Don't eat me!"
    
    a "(Surprised) It talks!"
    return

PoppySun
Newbie
Posts: 4
Joined: Mon Jun 04, 2018 7:39 pm
Projects: (Secret): Project Violet
Contact:

Re: (Basic Question) Replacing character portraits when the speaker changes?

#3 Post by PoppySun » Sun Nov 04, 2018 1:22 pm

Thank you very much, that's extremely helpful!

Post Reply

Who is online

Users browsing this forum: GetOutOfMyLab