[Solved] Dissolve on screen text in/out one letter at a 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
cccjjj
Newbie
Posts: 4
Joined: Mon May 14, 2018 4:09 pm
Contact:

[Solved] Dissolve on screen text in/out one letter at a time

#1 Post by cccjjj »

I've tried using search on here and google and exhausted every description for this I can think of. I'm real new, so I don't particularly understand the different transform/transition/animation methods very well but I'm good at figuring things out once I see how it works. I've kept what I'm doing relatively basic so far but this has stumped me and I'm stuck on trying to figure it out now.

I'm trying to make some text show up on screen with a dissolve in/out letter-by-letter animation, not necessarily in the center as I'd like to change the position a few times as well as the text itself. I just want it to show up one letter at a time and then disappear one letter at a time. I've tried forcing cps on the text but for whatever reason it just shows up as a regular dissolve and completely skips the cps part (I think I read it becomes an image so that might be why). That method also doesn't help with dissolving the text out one letter at a time, I'd guess.

To give you a VERY dirty and incomplete example of what I mean:

Code: Select all

    show text "{size=28}{alpha=0.7}O{alpha=0.3}O{alpha=0.0}OOOOOOOOOOOO{/alpha}{/alpha}{/alpha}{/size}" at center
    with Dissolve(0.1)
    hide text
    show text "{size=28}O{alpha=0.7}O{alpha=0.3}O{alpha=0.0}OOOOOOOOOOO{/alpha}{/alpha}{/alpha}{/size}" at center
    with Dissolve(0.1)
    hide text
    show text "{size=28}OO{alpha=0.7}O{alpha=0.3}O{alpha=0.0}OOOOOOOOOO{/alpha}{/alpha}{/alpha}{/size}" at center
    with Dissolve(0.1)
And so on, until it appears, and then do it again to make it disappear. This method works... but it's very time consuming and I assume it isn't very performance efficient (if that matters).
Last edited by cccjjj on Tue May 15, 2018 5:54 am, edited 1 time in total.

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: Dissolve on screen text in/out one letter at a time

#2 Post by kivik »

Interesting... I think it's definitely doable, so I had a go at it:

First we make a custom transform:

Code: Select all

transform custom_dissolve(timer, duration = 1.0):
    alpha 0.0
    pause timer
    linear 1.0 alpha 1.0
    pause duration
    linear 1.0 alpha 0.0
So we start the transform with our displayable invisible (alpha 0.0), pause it by a timer - this is important because we want our characters to appear one after another, then we start our dissolve in with a linear alpha statement, pause it for a while, before we fade it away again. I may have mistaken your intended effect but that's what I've gone for - you can delete the line pause duration and after if you don't want it to fade out again.

The timer and duration can be passed as parameters, so we can increase the timer per character when we show the text, so:

We loop through your string character by character, meanwhile using a screen variable, we increment the timer for each character, and apply the transform:

Code: Select all

screen custom_dissolve_text(string, x = 0.5, y = 0.5):
    default dissolve_timer = 0.0
    hbox:
        xpos x
        ypos y
        for char in string:
            text char at custom_dissolve(dissolve_timer)
            $ dissolve_timer += 0.1
To use it:

Code: Select all

call screen custom_dissolve_text("testing")
You can tweak the parameters for the transform to give yourself more control of course, but I think this achieves your basic idea. I quite enjoy playing with this :)

cccjjj
Newbie
Posts: 4
Joined: Mon May 14, 2018 4:09 pm
Contact:

Re: Dissolve on screen text in/out one letter at a time

#3 Post by cccjjj »

That is actually exactly what I was looking for. I can definitely work with this. Thanks a lot! I was trying to figure out how to use linear and alpha with transform last night as well, but I wasn't sure how to apply it. I already worked with those variables once to create a panning image, so I knew how that part worked, just not on text. You're amazing. Time to familiarize myself with this now.

cccjjj
Newbie
Posts: 4
Joined: Mon May 14, 2018 4:09 pm
Contact:

Re: Dissolve on screen text in/out one letter at a time

#4 Post by cccjjj »

Sorry for the double post. How do I make it return from call screen to my original label(correct word?)? I think I have a basic understanding of how call works, after looking it up in the docs, but putting a return/Return() in various places doesn't seem to do anything. So I guess I don't understand it well enough to know how to use it yet. Currently it just gets stuck after it dissolves out. Most of the threads I can find on this subject are dealing with buttons, but I don't have anything to click so I'm not sure what you do here.

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: Dissolve on screen text in/out one letter at a time

#5 Post by kivik »

Use show screen instead and put a pause before the next part of the story. If you don't want players to skip the animation, use a hard pause:

Code: Select all

show screen custom_dissolve_text("testing")
with Pause(4.0, hard=True)
hide screen custom_dissolve_text # for some reason it shows the animation again after the next line, possibly to do with screen redraw, so hide screen
"Hello World!"
Show screen should be used when you're not expecting an interaction or if the interaction is optional. Call screen should be used when interaction is needed before proceeding. I used call screen out of laziness to show the animation happening before the next line appears :P

cccjjj
Newbie
Posts: 4
Joined: Mon May 14, 2018 4:09 pm
Contact:

Re: Dissolve on screen text in/out one letter at a time

#6 Post by cccjjj »

Oh, my bad, I'm a dummy lmao. I thought when I tried show screen instead of call screen, and it ended the animation early, that that was the reason you said use call. So I didn't try to do anything else. Thanks again. It all makes sense now.

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: Dissolve on screen text in/out one letter at a time

#7 Post by kivik »

No problems at all! It takes some getting used to with showing vs calling screens, I still get confused sometimes with what's the best option! For example I don't really know why if I don't hide the screen it'd show the text again - although it's generally a good idea to hide a screen after not needing it as well :P

Post Reply

Who is online

Users browsing this forum: Google [Bot]