Crossfade between sprite expressions

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
Semicolonkid
Regular
Posts: 51
Joined: Tue Feb 14, 2017 6:13 pm
Projects: Summoned
itch: semicolonkid
Contact:

Crossfade between sprite expressions

#1 Post by Semicolonkid »

I'm a big fan of fading from expression to expression rather than having the sprite immediately switch between expressions/poses. However, you can't fade from one image to another in Ren'Py if both images share the same initial tag.

Right now, I've got a custom transform:

Code: Select all

transform my_dissolve(start, end, duration):
    alpha start
    linear duration alpha end
Which is used thusly:

Code: Select all

    "Some text."
    
    show image_1 at my_dissolve(0, 1, 0.5)
    "Some more text."
    
    show image_2 at my_dissolve(0, 1, 0.5)
This works because "image_1" and "image_2" don't have the same tag, so image_2 fades in on top of image_1 and it looks very nice - PROVIDED image_2 doesn't have any transparent background whatsoever for image_1 to peek through.
Furthermore, this custom transform allows the next line of text to be shown WHILE the crossfade happens, rather than after it happens (like if I used a regular dissolve), which I really like.

But, if I try something like this:

Code: Select all

    "We've added a 'Jim' tag."
    
    show Jim image_1 at my_dissolve(0, 1, 0.5)
    "So now these are both the same type of image."
    
    show Jim image_2 at my_dissolve(0, 1, 0.5)
Then instead, Jim image_1 will vanish immediately and then Jim image_2 will fade in on top of nothing. I understand why this happens. I just don't know what a good workaround is.

It's one thing if I'm fading a scene over a scene and they each have distinct tags. But a character sprite will not only share the same tag with alternate expressions of itself, it ALSO has transparency behind it. So, does anyone have an elegant solution for crossfading between expressions that could potentially use my custom transform function above?
Image

User avatar
Divona
Miko-Class Veteran
Posts: 678
Joined: Sun Jun 05, 2016 8:29 pm
Completed: The Falconers: Moonlight
Organization: Bionic Penguin
itch: bionicpenguin
Contact:

Re: Crossfade between sprite expressions

#2 Post by Divona »

Code: Select all

transform LiveDissolve(spriteB, duration=0.5):
    DynamicImage(spriteB) with Dissolve(duration, alpha=True)

label start:

    show Jim image_1
    "This is Jim."

    show Jim image_1 at LiveDissolve("Jim image_2")
    "This is Jim image_2."

    return
Completed:
Image

User avatar
Semicolonkid
Regular
Posts: 51
Joined: Tue Feb 14, 2017 6:13 pm
Projects: Summoned
itch: semicolonkid
Contact:

Re: Crossfade between sprite expressions

#3 Post by Semicolonkid »

Oh! DynamicImage. Huh.
Well, this works beautifully! Thank you!
Image

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], BadMustard