[Solved] Using MatrixColor to create Hair Colors in Character Creator?

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
Hojoo
Newbie
Posts: 20
Joined: Wed Sep 28, 2022 7:26 pm
Contact:

[Solved] Using MatrixColor to create Hair Colors in Character Creator?

#1 Post by Hojoo »

Hello! I'm fairly new to Ren'Py and would love help.

I'm working on a character creator for my game and have been trying to use the TintMatrix transform to recolor the sprites I'm using rather than recolor them separately. The part that I'm stuck on is how to get a tint to apply across different sprites in the same category, i.e. choosing a hair type and then a hair color.

Below are my default variables:

Code: Select all

default hair    =   1
default brows   =   1
default nose    =   1
default mouth   =   1

default body_color  =   1
default hair_color  =   1

$ body_tint = "#FFFFFF"
$ hair_tint = "#FFFFFF"
Below is part of a layeredimage:

Code: Select all

layeredimage Player:
    always:
        "images/character_creator/cc_base.png" matrixcolor TintMatrix(body_tint)
    always:
        ConditionSwitch(
            "nose==1","images/character_creator/cc_nose_1.png",
            "nose==2","images/character_creator/cc_nose_2.png") matrixcolor TintMatrix(body_tint)
    group brows:
        attribute brows_normal default:
            ConditionSwitch(
                "brows==1","images/character_creator/cc_brows_1.png",
                "brows==2","images/character_creator/cc_brows_2.png") matrixcolor TintMatrix(hair_tint)
        attribute brows_raised:
            "images/character_creator/cc_brows_raised.png" matrixcolor TintMatrix(hair_tint)
    group mouth:
        attribute mouth_normal default:
            ConditionSwitch(
                "mouth==1","images/character_creator/cc_mouth_1.png",
                "mouth==2","images/character_creator/cc_mouth_2.png") matrixcolor TintMatrix(body_tint)
        attribute mouth_smile:
            "images/character_creator/cc_mouth_smile.png" matrixcolor TintMatrix(body_tint)
    always:
        ConditionSwitch(
            "hair==1","images/character_creator/cc_hair_1.png",
            "hair==2","images/character_creator/cc_hair_2.png") matrixcolor TintMatrix(hair_tint)
Below is part of an imagemap using buttons to cycle through customization options, and trying to call a function to set tints:

Code: Select all

        hotspot( 90*7,  47*7,  5*7, 7*7) action [SetVariable("body_color",If(body_color==1,6, body_color-1)), Call("set_body_tint")]
        hotspot(130*7,  47*7,  5*7, 7*7) action [SetVariable("body_color",If(body_color==6,1, body_color+1)), Call("set_body_tint")]
        hotspot( 94*7,  63*7,  5*7, 7*7) action [SetVariable("brows",If(brows==1,3, brows-1)), Call("set_hair_tint")]
        hotspot(126*7,  63*7,  5*7, 7*7) action [SetVariable("brows",If(brows==3,1, brows+1)), Call("set_hair_tint")]
        hotspot( 90*7,  79*7,  5*7, 7*7) action [SetVariable("nose",If(nose==1,2, nose-1)), Call("set_body_tint")]
        hotspot(130*7,  79*7,  5*7, 7*7) action [SetVariable("nose",If(nose==2,1, nose+1)), Call("set_body_tint")]
        hotspot( 90*7,  87*7,  5*7, 7*7) action [SetVariable("mouth",If(mouth==1,3, mouth-1)), Call("set_body_tint")]
        hotspot(130*7,  87*7,  5*7, 7*7) action [SetVariable("mouth",If(mouth==3,1, mouth+1)), Call("set_body_tint")]
        hotspot( 98*7, 103*7,  5*7, 7*7) action [SetVariable("hair",If(hair==1,3, hair-1)), Call("set_hair_tint")]
        hotspot(122*7, 103*7,  5*7, 7*7) action [SetVariable("hair",If(hair==3,1, hair+1)), Call("set_hair_tint")]
        hotspot( 90*7, 104*7,  3*7, 5*7) action [SetVariable("hair_color",If(hair_color==1,2, hair_color-1)), Call("set_hair_tint")]
        hotspot( 94*7, 104*7,  3*7, 5*7) action [SetVariable("hair_color",If(hair_color==2,1, hair_color+1)), Call("set_hair_tint")]
Below are some functions to change tints:

Code: Select all

label set_body_tint:
    if body_color == 1:
        body_tint = "#C9823E"
    elif body_color == 2:
        body_tint = "#734C27"
    call screen chargen
label set_hair_tint:
    if hair_color == 1:
        hair_tint = "#DED6CE"
    elif hair_color == 2:
        hair_tint = "#3F75BA"
    call screen chargen
When I run the game, I get the errors that body_tint and hair_tint are not defined.
Is it possible to do something like this? Any help would be super appreciated.
Last edited by Hojoo on Fri Jan 06, 2023 7:34 pm, edited 5 times in total.

Hojoo
Newbie
Posts: 20
Joined: Wed Sep 28, 2022 7:26 pm
Contact:

Re: Using MatrixColor to create Hair Colors in Character Creator?

#2 Post by Hojoo »

It worked like this:

The same default variables, but tints declared as defaults instead of with $ and adding the line define config.gl2 = True because matrixcolor requires gl2 to function:

Code: Select all

default hair    =   1
default brows   =   1
default nose    =   1
default mouth   =   1

default body_color  =   1
default hair_color  =   1

default body_tint  = "#FFFFFF"
default hair_tint  = "#FFFFFF"

define config.gl2 = True
Defining player images separately, so that TintMatrix is applied to each beforehand:

Code: Select all

image cc_base:
    "images/character_creator/cc_base.png"
    matrixcolor TintMatrix(body_tint)
image cc_nose:         
    "images/character_creator/cc_nose_[nose].png"         
    matrixcolor TintMatrix(body_tint)
image cc_brows:     
    "images/character_creator/cc_brows_[brows].png" 
    matrixcolor TintMatrix(hair_tint) 
image cc_brows_raised: 
    "images/character_creator/cc_brows_raised.png"
    matrixcolor TintMatrix(hair_tint)
image cc_mouth:
    "images/character_creator/cc_mouth_[mouth].png"
    matrixcolor TintMatrix(body_tint)
image cc_mouth_smile:
    "images/character_creator/cc_mouth_smile.png"
image cc_hair:
    "images/character_creator/cc_hair_[hair].png"
    matrixcolor TintMatrix(hair_tint)
Then the layeredimage, which no longer evaluates whether a variable is true, and instead uses the values from the before defined images:

Code: Select all

layeredimage Player:
    always:
        "cc_base"
    always:
        "cc_nose"
    group brows:
        attribute brows_normal default:
            "cc_brows"
        attribute brows_raised:
            "cc_brows_raised"
    group mouth:
        attribute mouth_normal default:
            "cc_mouth"
        attribute mouth_smile:
            "cc_mouth_smile"
    always:
        "cc_hair"
The hotspots under the imagemap stay the same:

Code: Select all

        hotspot( 64,  33,  5, 7) action [SetVariable("body_color",If(body_color==1,6, body_color-1)), Call("set_body_tint")]
        hotspot(104,  33,  5, 7) action [SetVariable("body_color",If(body_color==6,1, body_color+1)), Call("set_body_tint")]
        hotspot( 68,  49,  5, 7) action [SetVariable("brows",If(brows==0,2, brows-1))]
        hotspot(100,  49,  5, 7) action [SetVariable("brows",If(brows==2,0, brows+1))]
        hotspot( 64,  65,  5, 7) action [SetVariable("nose",If(nose==1,2, nose-1))]
        hotspot(104,  65,  5, 7) action [SetVariable("nose",If(nose==2,1, nose+1))]
        hotspot( 64,  73,  5, 7) action [SetVariable("mouth",If(mouth==1,2, mouth-1))]
        hotspot(104,  73,  5, 7) action [SetVariable("mouth",If(mouth==2,1, mouth+1))]
        hotspot( 72,  89,  5, 7) action [SetVariable("hair",If(hair==0,2, hair-1))]
        hotspot( 96,  89,  5, 7) action [SetVariable("hair",If(hair==2,0, hair+1))]
        hotspot(102,  90,  3, 5) action [SetVariable("hair_color",If(hair_color==1,6, hair_color-1)), Call("set_hair_tint")]
        hotspot(106,  90,  3, 5) action [SetVariable("hair_color",If(hair_color==6,1, hair_color+1)), Call("set_hair_tint")]
And the functions stay the same:

Code: Select all

label set_body_tint:
    if body_color == 1:
        $ body_tint = "#C9823E"
    elif body_color == 2:
        $ body_tint = "#734C27"
    call screen chargen
label set_hair_tint:
    if hair_color == 1:
        $ hair_tint = "#DED6CE"
    elif hair_color == 2:
        $ hair_tint = "#3F75BA"
    call screen chargen

Post Reply

Who is online

Users browsing this forum: No registered users