Character image selection?

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
lemonokashi
Regular
Posts: 55
Joined: Mon Jan 13, 2014 11:46 pm
Contact:

Character image selection?

#1 Post by lemonokashi »

Sorry if this is a stupid question, but I wanted the option of choosing a male or female protagonist that will define character images without writing an if statement every time I need to show that character? For example is there any statement I could use to define a specific image command as using a different image depending on a user's choice at the beginning of the game?

User avatar
Suika
Regular
Posts: 99
Joined: Thu Oct 03, 2013 12:23 am
Contact:

Re: Character image selection?

#2 Post by Suika »

You could save the character image as a variable, and just access the variable whenever you need to display the character.

More specifically:
-User selects a character image (userSelection)
-Store userSelection in a variable (playerImage)
-Display playerImage whenever the player is to be shown.

Tsapas
Regular
Posts: 69
Joined: Mon Oct 14, 2013 8:18 am
Contact:

Re: Character image selection?

#3 Post by Tsapas »

I believe you are referring to side images? You can try this:

Code: Select all

$ pov = Character('Player', color="#F8BA87",show_side=ConditionSwitch("povGender == Male", "pov_male.png","povGender == Female", "pov_female.png"))

User avatar
OokamiKasumi
Eileen-Class Veteran
Posts: 1779
Joined: Thu Oct 14, 2010 3:53 am
Completed: 14 games released -- and Counting.
Organization: DarkErotica Games
Deviantart: OokamiKasumi
Location: NC, USA
Contact:

Re: Character image selection?

#4 Post by OokamiKasumi »

lemonokashi wrote:...I wanted the option of choosing a male or female protagonist that will define character images without writing an if statement every time I need to show that character? For example is there any statement I could use to define a specific image command as using a different image depending on a user's choice at the beginning of the game?
This is exactly what I did in my most recent game "Trap!"
-- I accomplished this by way of a ConditionSwitch in the image definitions.

First, you'll need to define ALL versions of your PC images with ConditionSwitch.
-- I only had 3 versions of each image: Neutral, Annoyed, and Concerned in Left & Right, making 6 total images in both male & female.

Code: Select all

init:
    image pc = "ch/male/mConR.png"
# ----------------------------------------------------
    image pc neuR = ConditionSwitch(
        "gender == 'female' ", Image ("ch/fem/fNeuR.png"),
        "gender == 'male' ", Image ("ch/male/mNeuR.png"),
        "True", Image ("ch/male/mNeuR.png"),
        )

    image pc neuL = ConditionSwitch(
        "gender == 'female' ", Image ("ch/fem/fNeuL.png"),
        "gender == 'male' ", Image ("ch/male/mNeuL.png"),
        "True", Image ("ch/male/mNeuL.png"),
        )
I created a whole separate .rpy page just for these definitions alone called "xLiveComposite.rpy".

Next, in script.rpy define your character so that it can be named.

Code: Select all

init:
    $ e = DynamicCharacter("pc_name", 
        color="#ffffcc",
        outlines = [(1, "#333300", 0, 0)],
        drop_shadow = (2, 2,),
        what_prefix="\"",
        what_suffix="\"",
        show_two_window = True,
        ctc="ctc_blink",
        ctc_position="fixed",)

    $ e_side = DynamicCharacter("pc_name", 
        color="#ffffcc",
        outlines = [(1, "#333300", 0, 0)],
        drop_shadow = (2, 2,),
        show_side_image=ConditionSwitch(
            "gender == 'female' ", "ch/fem/f_side.png",
            "gender == 'male' ", "ch/male/m_side.png",
            xalign=0.0, yalign=1.0),
        what_prefix="\"",
        what_suffix="\"",
        show_two_window = True,
        ctc="ctc_blink",
        ctc_position="fixed",)
Add the variable flags that will code in the player's gender selection and name:

Code: Select all

# -----------------------------------------
label start:
    $ pc = " "
    $ gender = " " 
Next, add the code that allows the player to choose their Gender and Name:

Code: Select all

#################################################
    scene bg_02
    show gal at right
    show guy at left 
    with fade
    
    menu:
        "Would you like a Male Lead character?":
            $ gender = 'male'
            hide gal with dissolve
            show guy at center with move

        "Or a Female Lead character?":
            $ gender = 'female'
            hide guy with dissolve
            show gal at center with move
            
label name:
    $ pc_name = renpy.input("What would you like to name your character? \n{i}{color=#cccc99} -- Backspace to erase the current name. When you're done, hit Enter.{/color}{/i}\n", "Chris", length=15)
    $ pc_name = pc_name.strip()
    
    scene black with fade    
Your game officially starts after this point.

Done this way, you can simply show, hide, and transition your character image just like any other image -- without the need of any extra flags. :)

Code: Select all

    show pc neuL at right with moveinright
I hope that helps.
Ookami Kasumi ~ Purveyor of fine Smut.
Most recent Games Completed: For ALL my completed games visit: DarkErotica Games

"No amount of great animation will save a bad story." -- John Lasseter of Pixar

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Character image selection?

#5 Post by xela »

lemonokashi wrote:Sorry if this is a stupid question, but I wanted the option of choosing a male or female protagonist that will define character images without writing an if statement every time I need to show that character? For example is there any statement I could use to define a specific image command as using a different image depending on a user's choice at the beginning of the game?
There are to many ways of doing this... best way is to sort all of the images in two folders (male/female), bulkload them into the game and allow player to pic one.
Like what we're doing? Support us at:
Image

lemonokashi
Regular
Posts: 55
Joined: Mon Jan 13, 2014 11:46 pm
Contact:

Re: Character image selection?

#6 Post by lemonokashi »

That is so helpful! Thank you very much!

Post Reply

Who is online

Users browsing this forum: Google [Bot]