[SOLVED] Adding tint to the image based on the variable

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
_ticlock_
Miko-Class Veteran
Posts: 910
Joined: Mon Oct 26, 2020 5:41 pm
Contact:

[SOLVED] Adding tint to the image based on the variable

#1 Post by _ticlock_ »

Hello, All,

I am trying to figure out if there is a way to pass a variable to the transform in the dynamic image. For example, use a variable to pass color to TintMatrix.

Let's say we have dynamic image:

Code: Select all

image mc_outfit = "mc_[outfit].png"
Changing the variable outfit we can change the image mc_outfit. In this case, the dynamic image has text interpolation performed at the start of each interaction.

However, what if we want to add a tint to the image:

Code: Select all

image mc_outfit:
    "mc_[outfit].png"
    matrixcolor TintMatrix("#ffa")
That is a simple way for some customization without creating additional image files for different colors.

The question is if we can pass a parameter to the TintMatrix using another variable something like:

Code: Select all

default chosen_color = "#ffa"
image mc_outfit:
    "mc_[outfit].png"
    matrixcolor TintMatrix(chosen_color)
I tried to use text string hoping that interpolation would be performed for the transform parameter:

Code: Select all

default chosen_color = "#ffa"
image mc_outfit:
    "mc_[outfit].png"
    matrixcolor TintMatrix("[chosen_color]")
but it does not.

Is it a simple way to make a tint to the image based on the variable?
Last edited by _ticlock_ on Fri Jul 22, 2022 11:13 pm, edited 1 time in total.

User avatar
_ticlock_
Miko-Class Veteran
Posts: 910
Joined: Mon Oct 26, 2020 5:41 pm
Contact:

Re: Adding tint to the image based on the variable

#2 Post by _ticlock_ »

Potentially I could create a variable in the init to make it work, but I can't shake the feeling that this solution smells some problems later.

Code: Select all

init python:
    if 'chosen_color' not in globals():
        chosen_color = "#ffa"
        
image mc_outfit:
    "mc_[outfit].png"
    matrixcolor TintMatrix(chosen_color)
Especially, taking into account that I would like to store colors inside classes.

I feel like I am missing something obvious.

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: Adding tint to the image based on the variable

#3 Post by Remix »

You could use a displayable prefix to push the image through a function...

Example using substituted global tint variable

Code: Select all


init -10 python:

    def tint_layer(s):

        split_parts = renpy.substitute(s).rsplit(" ",1)

        tint = "#FFF" if len(split_parts) == 1 else split_parts[1]

        try:

            tint = Color(tint)

        except:

            raise ValueError, "Could not interpret tint from {}".format(tint)

        return Transform(split_parts[0], matrixcolor=TintMatrix(tint))


    config.displayable_prefix["tint"] = tint_layer

default shirt_tint = "#F00"

image mc_outfit = "tint:mc_[outfit].png [shirt_tint]"
Changes colour if shirt_tint changes...

For class attributes maybe pass both the instance and attribute as strings (with rsplit(" ", 2) ) then getattr(instance, attr) to retrieve the tint
Frameworks & Scriptlets:

User avatar
_ticlock_
Miko-Class Veteran
Posts: 910
Joined: Mon Oct 26, 2020 5:41 pm
Contact:

Re: Adding tint to the image based on the variable

#4 Post by _ticlock_ »

Remix wrote: Thu Jul 14, 2022 7:00 pm You could use a displayable prefix to push the image through a function...
Wow. That seems promising. Is it any reason why you would not recommend using this approach? (Like it may slow down displayable processing (besides using tint) or complicate anything else)

Thank you for your help!!!

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: Adding tint to the image based on the variable

#5 Post by Remix »

I cannot think of any reason not to use an approach like this.
Frameworks & Scriptlets:

Post Reply

Who is online

Users browsing this forum: No registered users