Darkening sprites over time

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
faylar
Newbie
Posts: 7
Joined: Tue Apr 19, 2016 9:02 pm
Contact:

Darkening sprites over time

#1 Post by faylar » Tue Apr 19, 2016 10:22 pm

Hi everyone!

I just started experiementing with renpy and everything has been great so far, but I'm slowly trying to do more advanced stuff.

So the effect I'm trying to do now is to "darken sprites".

Yes, I know there are already a few threads in the forums with this, and I already know the gist of executing it, so hear me out a bit.

To push for polishness, what I want to do is to be able to interpolate images between the normal image and the darkened image. (Yes, I am aware of the silhouette post: https://www.renpy.org/wiki/renpy/doc/co ... silhouette)

The ideal code snippet in my mind goes like:

Code: Select all

show person at darken
where darken is a transform that multiplies the original color of the image over time, but I could not find a color multiply property that I can use in transform (there is additive though, somehow).

So the first question is whether there is a way to achieve this?
If there is, then my problem is solved for all cases.

If not, then I would have to create a darkened silhouette version of the image, place it on top of the image I want, and increase it's alpha over time etc...

For this method, I'm looking for a cleaner way to do this.

The main problem is that it will become very annoying to manage 2 separate images that will ALWAYS share the same position and size. If I have 4 characters on screen, that means 8 images to manage. If each character has 2 different poses, that means 12 images to manage.

The thought of moving characters and their darkened images around makes me dizzy. Feels alot to do just for darkening an image.

Does anyone have any suggestions to make the management and code base lighter (helper functions, etc)?

That's all.

Sorry for the long ranty post.

User avatar
nyaatrap
Crawling Chaos
Posts: 1824
Joined: Mon Feb 13, 2012 5:37 am
Location: Kimashi Tower, Japan
Contact:

Re: Darkening sprites over time

#2 Post by nyaatrap » Tue Apr 19, 2016 10:57 pm

There is no transform property, but transform is any function that takes displayable as argument and returns displayable. So if there is a python function, then you can use it in transform. Code would be something like this (untested)

Code: Select all

transform alphatransform:
    alpha .0
    linear 1.0 alpha 1.0

init python:
    def shade_transform(d):
        return AlphaBlend(alphatransform, d, Solid("#000", xysize=(x, y)), True)


label:
    show sprite at shade_transform

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

Re: Darkening sprites over time

#3 Post by philat » Wed Apr 20, 2016 12:05 am

If you intend to use it to show who's talking (this seems to be the most common use case for darkened sprites), I've found that I prefer to use a TransitionConditionSwitch coupled with character callbacks to get it working automatically. It's been a while since I used it in one of my games (quite a few versions of renpy ago), so I can't say for certain if it still works, but TransitionConditionSwitch was written by Asceai here on the forums and at least as of a year or so ago-ish, I had it working with no problem. A bit more work upfront, but basically plug-and-forget once you've got it going.

TransitionConditionSwitch outlined here (scroll down to see the various posts on bug fixes): viewtopic.php?f=51&t=26612

Basic method:

1. Use im.MatrixColor to create darkened sprites: https://www.renpy.org/doc/html/displaya ... atrixcolor (caveat that im.MatrixColor only works with images, not displayables like LiveComposite -- if you're using the latter, use AlphaBlend)

2. Create TransitionConditionSwitches where the condition is the speaker and the images are normal / darkened sprites (the basic concept of character callbacks and keeping track of speaker is best shown with an example: take a look at the blink/lip flap code here https://www.renpy.org/wiki/renpy/doc/co ... d_Lip_Flap )

- side note: You can functionalize a lot of steps 1 and 2. Well, at least you can definitely functionalize 1 (check out auto image declaration code in the cookbook) and you should be able to do 2 although I haven't tried; I didn't need it, because I only had a few sprites).

3. Use the TCS image -- will automatically be normal when speaking, darkened when not.

faylar
Newbie
Posts: 7
Joined: Tue Apr 19, 2016 9:02 pm
Contact:

Re: Darkening sprites over time

#4 Post by faylar » Wed Apr 20, 2016 12:44 am

Thanks for the reply everyone.
philat wrote: If you intend to use it to show who's talking
I'm intending to have full control of this effect and have shuffling of characters going back and forth between the foreground and background so this would not suffice (I have already checked all those threads, but thanks for helping 8) )

Thanks nyaatrap for the code snippet and also philat for suggesting AlphaBlend though. I'm still a noob when trying to combine ATL and normal code. I will play around with the snippet once when get home and try to get it running.

EDIT: just a hunch (maybe even a dumb question) but for

Code: Select all

return AlphaBlend(alphatransform, d, Solid("#000", xysize=(x, y)), True)
Solid() fills a rect right? So if I want the character image itself to be blended, I need instead a solid black silhouette of the character instead right?

EDIT2: oh wait! I just read about the alpha flag, hmmm

User avatar
nyaatrap
Crawling Chaos
Posts: 1824
Joined: Mon Feb 13, 2012 5:37 am
Location: Kimashi Tower, Japan
Contact:

Re: Darkening sprites over time

#5 Post by nyaatrap » Wed Apr 20, 2016 2:23 am

My mistake

Code: Select all

return AlphaBlend(alphatransform(d), d, Solid("#000", xysize=(x, y)), True)
was correct. The third argument (Solid) is blended over the second argument (d), on area of the first argument (alphatransform(d)).

faylar
Newbie
Posts: 7
Joined: Tue Apr 19, 2016 9:02 pm
Contact:

Re: Darkening sprites over time

#6 Post by faylar » Sat May 07, 2016 6:03 am

I'm sorry for bumping this post again, but this is a slight extension of the question I have.

Is it possible to pass more variables into the ATL transform function?

like

Code: Select all

transform alphatransform(duration):
    alpha .0
    linear duration alpha 1.0

#this does not work of course
return AlphaBlend(alphatransform(d, duration=0.5), d, Solid("#000", xysize=(x, y)), True)
I'm having trouble finding (or maybe understanding?) the documentations regarding using ATL-ish code in normal python code, and vice versa.

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Darkening sprites over time

#7 Post by xela » Sat May 07, 2016 6:29 am

Maybe something like:

Code: Select all

transform alphatransform(d, duration):
    d
    alpha .0
    linear duration alpha 1.0
?

It should definitely be possible...
Like what we're doing? Support us at:
Image

Post Reply

Who is online

Users browsing this forum: Google [Bot], Karrion