How to use 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: 1
Joined: Wed Sep 28, 2022 7:26 pm
Contact:

How to use MatrixColor to create Hair Colors in Character Creator?

#1 Post by Hojoo » Wed Sep 28, 2022 8:31 pm

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 a 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, as I am very lost.

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], Majestic-12 [Bot]