Using MatrixColor Opacity Matrix in a python function?

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
BunnyInfernal
Regular
Posts: 34
Joined: Wed Dec 26, 2018 10:45 am
Contact:

Using MatrixColor Opacity Matrix in a python function?

#1 Post by BunnyInfernal »

This question is a bit of a follow-up to my post here:

The suggestion from m_from_space was to use im.MatrixColor, but I was pretty sure that image manipulators were not the recommended way to go forward.

Is there a way to use OpacityMatrix from inside a python function for a DynamicDisplayable? My plan is to have the value change base on an in-game variable.

So far, my in-progress code looks a bit like this:

Code: Select all

default tan_image_loc = "images/avatar/tanned.webp"
default mask_image_1p_loc = "images/avatar/1p_msk.webp"

init python:

    def tanlines1(st, at):

        ## The plan is to use this for different images, so those will change via variable, too
        tan_image =  DynamicImage(tan_image_loc)
        mask_image_1p = DynamicImage(mask_image_1p_loc)

        mask_modified = ??????? ## Looking to change opacity based on in-game value - matrixcolor OpacityMatrix(mask_image_1p, 0.5)?
        
        ## Create mask
        img_tan = AlphaMask(tan_image, mask_modified)

        return img_tan, None

image tannedtest1 = DynamicDisplayable(tanlines1)

User avatar
m_from_space
Miko-Class Veteran
Posts: 950
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: Using MatrixColor Opacity Matrix in a python function?

#2 Post by m_from_space »

You really shouldn't create more dynamic images inside a function for dynamic images. What's the point? The function gets called after every interaction and you can calculate the changes of all the images it contains inside it. Also your dynamic images would be local variables, that won't get executed again I assume. This feels like a performance issue to me.

Changing opacity the way I suggested works perfectly fine by the way, just try it out!

BunnyInfernal
Regular
Posts: 34
Joined: Wed Dec 26, 2018 10:45 am
Contact:

Re: Using MatrixColor Opacity Matrix in a python function?

#3 Post by BunnyInfernal »

m_from_space wrote: Sat Aug 20, 2022 3:52 am You really shouldn't create more dynamic images inside a function for dynamic images. What's the point? The function gets called after every interaction and you can calculate the changes of all the images it contains inside it. Also your dynamic images would be local variables, that won't get executed again I assume. This feels like a performance issue to me.
Unfortunately, I'm not really sure what I'm doing, code-wise, so I've been throwing things together just as an experiment. :lol: But, yes, that probably wasn't a good way to do it.

m_from_space wrote: Sat Aug 20, 2022 3:52 am Changing opacity the way I suggested works perfectly fine by the way, just try it out!
I updated that thread with my findings, with the only issue I ran into being that I couldn't use images--it had to be a file path or a string variable with the path. Other than that, it worked fine.

My concern is that I keep seeing comments that Image Modifiers shouldn't be used anymore. Here's the section from the documentation:

https://www.renpy.org/doc/html/im.html
An image manipulator can be used any place a displayable can, but not vice-versa. An Image() is a kind of image manipulator, so an Image can be used whenever an image manipulator is required.

With the few exceptions listed below, the use of image manipulators is historic. A number of image manipulators that had been documented in the past should no longer be used, as they suffer from inherent problems. In any case except for im.Data, the Transform() displayable provides similar functionality in a more general manner, while fixing the problems, although it sometimes requires gl2 to be enabled.
So that had be a bit concerned and curious if there's a way of doing this that's considered "correct" by current RenPy standards.

enaielei
Veteran
Posts: 293
Joined: Fri Sep 17, 2021 2:09 am
Organization: enaielei
Tumblr: enaielei
Deviantart: enaielei
Github: enaielei
Skype: enaielei
Soundcloud: enaielei
itch: enaielei
Discord: enaielei#7487
Contact:

Re: Using MatrixColor Opacity Matrix in a python function?

#4 Post by enaielei »

BunnyInfernal wrote: Fri Aug 19, 2022 5:54 pm Is there a way to use OpacityMatrix from inside a python function for a DynamicDisplayable? My plan is to have the value change base on an in-game variable.
Have you tried using Transform for the mask then use alpha?

Code: Select all

mask = Transform("mask.png", alpha=variable)

BunnyInfernal
Regular
Posts: 34
Joined: Wed Dec 26, 2018 10:45 am
Contact:

Re: Using MatrixColor Opacity Matrix in a python function?

#5 Post by BunnyInfernal »

enaielei wrote: Sat Aug 20, 2022 11:45 am Have you tried using Transform for the mask then use alpha?
No, can't say that I have. I don't think that method even occurred to me.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot]