Automatically darkening characters that aren't speaking, layered image version

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
solarProtag
Regular
Posts: 37
Joined: Sun May 28, 2017 12:17 am
Completed: http://solarprotag.weebly.com/gamedev.html
Projects: Battle Live Series
Tumblr: solarasketchbook
itch: solarprotagonist
Contact:

Automatically darkening characters that aren't speaking, layered image version

#1 Post by solarProtag »

Hi there.

So I've been trying to figure out a way to automatically darken images when those associated characters aren't speaking, specifically for layered image formatted ones.
I do know that using the matrixcolor ATL works on layered images, but right now I'd have to manually assign that matrix like:

Code: Select all

show character at darken
every time those specific characters aren't speaking. Frankly it's a bit too much and I'd like to automate it somehow.

I know that _last_say_who works in layered images, but that only works to add new attributes on top of your image, not alter the layered image as a whole itself.
If anyone could help out, I'd greatly appreciate it (and I'd also rather not use condition switches since that's why I use layered images now).
Thanks!

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2402
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Automatically darkening characters that aren't speaking, layered image version

#2 Post by Ocelot »

One thing I could think about is that layered image is still a Displayable, you can apply any effects to, or compose with different displayables. Simplest way would be use ConditionSwitch to apply transform to layered image depending on _last_say_who variable.
< < insert Rick Cook quote here > >

User avatar
solarProtag
Regular
Posts: 37
Joined: Sun May 28, 2017 12:17 am
Completed: http://solarprotag.weebly.com/gamedev.html
Projects: Battle Live Series
Tumblr: solarasketchbook
itch: solarprotagonist
Contact:

Re: Automatically darkening characters that aren't speaking, layered image version

#3 Post by solarProtag »

That would require making a ConditionSwitch with my already defined layered image, right?
Hm, that could work. Though won't that inflate my file sizes or is a ConditionSwitch not as taxing as I assume it is?

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2402
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Automatically darkening characters that aren't speaking, layered image version

#4 Post by Ocelot »

ConditionSwitch does not create anything physically on disk. And layered image is technically already a Composite of ConditionSwitches with some corners cut.
It should not impact perfomance.
< < insert Rick Cook quote here > >

User avatar
solarProtag
Regular
Posts: 37
Joined: Sun May 28, 2017 12:17 am
Completed: http://solarprotag.weebly.com/gamedev.html
Projects: Battle Live Series
Tumblr: solarasketchbook
itch: solarprotagonist
Contact:

Re: Automatically darkening characters that aren't speaking, layered image version

#5 Post by solarProtag »

Alright, that's good to hear.
I'll go test it out and see how it fares, thank you!

User avatar
solarProtag
Regular
Posts: 37
Joined: Sun May 28, 2017 12:17 am
Completed: http://solarprotag.weebly.com/gamedev.html
Projects: Battle Live Series
Tumblr: solarasketchbook
itch: solarprotagonist
Contact:

Re: Automatically darkening characters that aren't speaking, layered image version

#6 Post by solarProtag »

Sorry to add onto this, but now I'm a little stuck on how to format the ConditionSwitch so it'll work with my layered image.

philat
Eileen-Class Veteran
Posts: 1910
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Automatically darkening characters that aren't speaking, layered image version

#7 Post by philat »

You can just wrap the whole image in a matrixcolor transform now, I'm pretty sure.

Code: Select all

transform grayscale:
    matrixcolor SaturationMatrix(0.0)

define testchar = Character("test", image="test")
image test speaking = "yourimage"
image test = At("yourimage", grayscale)

define config.speaking_attribute = "speaking"
# https://www.renpy.org/dev-doc/html/config.html#var-config.speaking_attribute

label start:

    "1"
    show test
    "2"
    testchar "3"
    "4"
    testchar "5"
    "6"

User avatar
solarProtag
Regular
Posts: 37
Joined: Sun May 28, 2017 12:17 am
Completed: http://solarprotag.weebly.com/gamedev.html
Projects: Battle Live Series
Tumblr: solarasketchbook
itch: solarprotagonist
Contact:

Re: Automatically darkening characters that aren't speaking, layered image version

#8 Post by solarProtag »

I hope this doesn't come off as dude, but that doesn't really solve my problem since that prevents me from calling the attributes in my layered images.

philat
Eileen-Class Veteran
Posts: 1910
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Automatically darkening characters that aren't speaking, layered image version

#9 Post by philat »

Caveat that I don't really use layered images, but I'm pretty sure you can also add normal attributes other than speaking_attribute as needed. Quick search shows a couple hits here that use speaking_attribute with layered images.

ETA: Eh, my bad. Grabbed a layeredimage example to take a look, seems just wrapping the whole thing with an At() will override the attributes. Just defining a new layered image should still work though.

Code: Select all

layeredimage test:
   at grayscale
   [stuff goes here]

layeredimage test speaking:
   [stuff goes here]

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: Automatically darkening characters that aren't speaking, layered image version

#10 Post by Remix »

Another approach is to set a default transform that passes an image name into a Python function and uses that to adjust the darkness...

Code: Select all

image eileen = Solid("#F00", xysize=(200, 400))
image lucy = Solid("#F4F", xysize=(200, 400))
image lucy happy = Solid("#4FF", xysize=(200, 400))

define e = Character("Eileen", image="eileen")
define l = Character("Lucy", image="lucy")

transform pop_char(tag=None):
    function renpy.curry(pop_character)(tag=tag)

init python:

    def pop_character(trans, st, at, tag=None):
        trans.mesh = True

        adjust = 0.005 if tag == renpy.get_say_image_tag() else -0.005

        ### Tweak as wanted below...

        trans.zoom = min(1.1, max(1.0, trans.zoom + adjust))

        try:
            value = trans.matrixcolor.value
        except:
            value = 0.0
        trans.matrixcolor = BrightnessMatrix(
            min(0.0, max(-0.5, value + adjust * 5.0)))

        return 0.0

    config.tag_transform["eileen"] = pop_char("eileen")
    config.tag_transform["lucy"] = pop_char("lucy")


label start:

    # Images shown with at clauses will NOT use the tag_transform
    # show eileen at left

    # Images shown with colon then transform name(s) will also use the tag transform
    show eileen:
        left
    show lucy:
        right

    pause

    e "Me"
    l "No, me"
    e "Me, me, me"
    l happy "Umm... Me -- Now happy blue"
    "Neither"

    return
This:
1) Allows the transform to be added without coding it to each line (though existing transforms using at will need tweaks)
2) Allows animation between the states
3) Allows use on multi texture images like Composites or Live2D due to the mesh True setting
4) Does not require defining any new images (as it just uses get_say_image_tag)

This example also pops the character when speaking... Shouldn't be hard to find and remove that bit if unwanted.
Frameworks & Scriptlets:

User avatar
solarProtag
Regular
Posts: 37
Joined: Sun May 28, 2017 12:17 am
Completed: http://solarprotag.weebly.com/gamedev.html
Projects: Battle Live Series
Tumblr: solarasketchbook
itch: solarprotagonist
Contact:

Re: Automatically darkening characters that aren't speaking, layered image version

#11 Post by solarProtag »

That second method could be just what I'm looking for, and definitely can be built further.

Thanks!

Post Reply

Who is online

Users browsing this forum: No registered users