FancyText: Effects for Slow Text Display

A place for Ren'Py tutorials and reusable Ren'Py code.
Forum rules
Do not post questions here!

This forum is for example code you want to show other people. Ren'Py questions should be asked in the Ren'Py Questions and Announcements forum.
Message
Author
User avatar
yukinogatari
Newbie
Posts: 10
Joined: Thu Jul 16, 2020 5:26 am
Github: yukinogatari
Contact:

FancyText: Effects for Slow Text Display

#1 Post by yukinogatari »

What is this?

FancyText is a simple drop-in module for Ren'Py 7.3.5 7.5.2/8.0.2 that lets you display text on screens with a little more pizazz than vanilla. In simpler terms, it lets you add fade-in or slide or rotation effects to slow text display.

Click the image below to see a quick sample of what FancyText is capable of doing.

example.gif

Where can I get it?

You can download the code from the FancyText GitHub repository.

How do I use it?

Simply drop 01_fancytext.rpy into your game's directory and you'll have access to the new fancytext screen language statement. fancytext is identical to the built-in text, but with three new parameters added.
  • slow_effect: An effect that applies to each character of text as it's being displayed.
  • slow_effect_delay: The time, in seconds, slow_effect will take to complete.
  • always_effect: An effect that applies to each character of text for the duration that it's on-screen, after slow_effect has completed.
For specific examples and to see the effects in action, check out script.rpy, or drop the whole file into a new project.

Included Effects

Effects that begin with slow_ are for use with the slow_effect parameter. Effects that have parameters must have those parameters provided. Slow effects only work when the text cps is set to something other than 0, and animate across the text at the rate of text display.
  • slow_typewriter: A non-effect that replicates the built-in typewriter effect.
  • slow_fade: Slowly fades characters in over slow_effect_delay seconds.
  • slow_slide_up(y = 20): Slides the text up y pixels into place over slow_effect_delay seconds.
  • slow_slide_down(y = 20): Slides the text down y pixels into place over slow_effect_delay seconds.
  • slow_slide_right(x = 20): Slides the text right x pixels into place over slow_effect_delay seconds.
  • slow_slide_left(x = 20): Slides the text left x pixels into place over slow_effect_delay seconds.
  • slow_shake(x = 0, y = 0): Causes each character to shake for slow_effect_delay seconds with an intensity of x horizontal pixels and y vertical pixels.
  • slow_rotate: Causes each character to rotate 360 degrees over slow_effect_delay seconds.
  • slow_shaking_slide(shake_x = 0, shake_y = 0, slide_x = 0, slide_y = 0): A combination of slow_shake and the slow_slide functions.
  • slow_nonsense: Changes the position, alpha, and angle of every character wildly over slow_effect_delay seconds.
Effects that begin with always_ are for use with the always_effect parameter, and will affect the text for as long as it's on screen.
  • always_shake(x = 0, y = 0): Causes each character to shake with an intensity of x horizontal pixels and y vertical pixels.
  • always_pulse: Causes the text to slowly cycle between visible and invisible.
How does it work?

FancyText is a basic modification of the built-in Text that expands rendering to apply a small range of transformations to each individual glyph as it's displayed to the screen in slow mode. In effect, this allows you to expand on the default typewriter style, adding fades or slides or rotations to text as it appears.

It does so by hijacking the unused alpha property on Blit objects to store a Transform, applying the values of alpha, xoffset, yoffset, and rotate (no support for changing the center of rotation) to each individual glyph every time it's drawn. This means FancyText is, unsurprisingly, more resource-intensive than default text rendering.

The Transform objects are created by a function that takes three parameters: st, gt, and delay—the current time, the time the current glyph is expected to begin displaying, and the amount of time the glyph has allotted to complete displaying. This is similar to how ATL functions work, only applied to every character over the duration of the line displaying.

There also exists functions for transforming the text constantly, which I've dubbed "always effects." They work the same way as slow effects, take effect after any slow effect is complete, and have no "end" time. They continue to update until the user clicks past the line. I honestly can't think of any really practical use for this, but practicality's never stopped me from doing anything before.

You can look inside 01_fancytext.rpy to see a bunch of example functions and how they work.

FancyText effectively patches a few functions into the Text class, so it relies on a bunch of assumptions about how the Text class works in this specific version (7.3.57.5.2/8.0.2). This is generally known as "a bad idea," and as such, I cannot guarantee it will work with any past or future versions of Ren'Py.

Why not make a pull request?

Because, in short, this code is terrible. I programmed it this way for simplicity of implementation and speed of experimentation, sacrificing things like efficiency and modularity in the process. It's a bunch of dirty hacks to do something the text system is only kind of designed for, but it was cool enough to want to share.

That said, if someone wants to expand this into a proper animation feature for text, they are more than welcome to.

Can I use it for ____?

Yes. FancyText is released under the MIT license, the same license as Ren'Py itself. A good portion of the code is copied and modified from Ren'Py's source code, so it seemed only reasonable to release it under the same license.

Why did you make this???

I needed a gentle fade-in effect on my text for something, and searching the forum only led me to other users requesting the same thing going back years. That need combined with tax-related depression and a complete lack of concern for real-world practicality led to this crime against good coding practices.

Disclaimers and stuff

Honestly, I haven't tested this very much, so I can't guarantee it won't horribly break things in games more complicated than the tutorial. If you do run into any problems though, please feel free to let me know.

A lot of the included effects aren't practical, and should probably not be used in actual games, except sparingly. I'm not going to stop you from making a character that talks in slow_nonsense, though.
Last edited by yukinogatari on Mon Aug 29, 2022 5:03 pm, edited 1 time in total.

abysswatcher
Regular
Posts: 42
Joined: Sun Apr 12, 2020 11:50 pm
Projects: To-Live:The Struggle
Organization: Youyu de Shijie(憂鬱的世界)
Github: LuYifeng112
itch: https://luyifeng.itc
Location: New Zealand
Contact:

Re: FancyText: Effects for Slow Text Display

#2 Post by abysswatcher »

This is really cool! Thanks for the amazing code and effects!
The goal of the revolution is to achieve the people's rights, but during the course of the revolution, we must stress military power - and the two are mutually contradictory.
-Sun Yat-sen
"Become a Visual Novel writer they said, it will be fun" (little did they know they were right)

User avatar
Tayruu
Regular
Posts: 141
Joined: Sat Jul 05, 2014 7:57 pm

Re: FancyText: Effects for Slow Text Display

#3 Post by Tayruu »

Hell yeah, a soft fade to the typewriter effect is just the sort of thing I've been after myself. Shaking text is a neat and possibly useful effect too.

There's a few minor hiccups though.

- Fancytext doesn't like text outlines. If the dialogue has an outline style, it throws an error.

Code: Select all

While running game code:
  File "game/sc_00_debug.rpy", line 60, in script
    hawke "My name is Hawke."
  File "game/_init_s_fancytext.rpy", line 271, in render
    oblits = outline_blits(blits, o)
NameError: global name 'outline_blits' is not defined
- Any introductory effect replays after mid-message pauses. Tested with slow_fade and slow_nonsense and {w}/{w=x} tags.)
- This also appears to affect extend. I use extend to show menus at the end of dialogue, like so:

Code: Select all

    inu "I woke up in this forest,{w=0.4} and with this body,{w=0.6} and I haven't found anyone else around."
    show hawke neutral
    pause(0.4)
    label debug_dialogue_a1:
    menu:
        extend ""
        [menu starts here]
With the default text function, this effect is seamless. With fancytext, there's a noticeable jump and the text disappears for a moment as it regenerates the whole line again.

- Not easily implemented with the nvl screen, though this seems to be a fault of nvl not liking to have arguments. I can still put fancytext what id what_id slow_effect slow_fade slow_effect_delay 0.1 in the nvl screen itself without worry.

... I really love slow_nonsense though. If that madness could be centered on the line more than come from above, it might be a good effect.

User avatar
yukinogatari
Newbie
Posts: 10
Joined: Thu Jul 16, 2020 5:26 am
Github: yukinogatari
Contact:

Re: FancyText: Effects for Slow Text Display

#4 Post by yukinogatari »

Thanks for the reports, and I'm glad you're enjoying the effects! I've pushed an update to the repository that should fix the outline issue and text reanimating. The sample script you posted appears to run as expected now~ Let me know if you run into any other issues!

At some point when I have more time, I may try and make it possible to adjust the center of rotation for the rotation effects (matrices are hard and it's been years since I last thought about linear algebra lmao).

User avatar
Tayruu
Regular
Posts: 141
Joined: Sat Jul 05, 2014 7:57 pm

Re: FancyText: Effects for Slow Text Display

#5 Post by Tayruu »

I can confirm that the repeating of the animation on extend and wait tags is fixed, as well as outlines.

... oops, turns out that pause was literally the pause(0.4) in that code. Wonder why that was there.
Regardless, it seems all smooth sailing. o:

User avatar
Perihelion
Regular
Posts: 25
Joined: Tue Jul 22, 2014 5:45 pm
Projects: The Devil's Broker
Contact:

Re: FancyText: Effects for Slow Text Display

#6 Post by Perihelion »

This is really cool! Thanks for this. Unfortunately the alpha manipulation seems to be broken in the nightly build. Any plans to get it working with nightly?

User avatar
yukinogatari
Newbie
Posts: 10
Joined: Thu Jul 16, 2020 5:26 am
Github: yukinogatari
Contact:

Re: FancyText: Effects for Slow Text Display

#7 Post by yukinogatari »

I'll probably update it for the next stable release, but I'm a bit too busy to look into the nightlies.

User avatar
Wudgeous
Regular
Posts: 58
Joined: Tue Apr 30, 2019 5:59 am
Tumblr: herotome
itch: wudgeous
Contact:

Re: FancyText: Effects for Slow Text Display

#8 Post by Wudgeous »

I just wanted to say this is one of the coolest things I've ever seen for ren'py. I especially love the AAAAAAAAAAA, it reminds me of the blustery Winnie the Pooh episode. (:
Have confidence. Let go of perfectionism. I love you!
Image
A superhero dating sim in fresh hot development!


You can also keep up with me on Twitter and Itch!

User avatar
Perihelion
Regular
Posts: 25
Joined: Tue Jul 22, 2014 5:45 pm
Projects: The Devil's Broker
Contact:

Re: FancyText: Effects for Slow Text Display

#9 Post by Perihelion »

yukinogatari wrote: Wed Aug 05, 2020 1:47 am I'll probably update it for the next stable release, but I'm a bit too busy to look into the nightlies.
No problem. Looks like the issue was that it needed to use the new shader system. I fixed it by replacing this:

Code: Select all

char.alpha = trans.alpha
with this:

Code: Select all

char.add_shader("renpy.alpha")
char.add_uniform("u_renpy_alpha", trans.alpha)
char.add_uniform("u_renpy_over", 1.0)
You could probably also use this to add any other shader you wanted, which would open up a cool range of new effects. :)

User avatar
yukinogatari
Newbie
Posts: 10
Joined: Thu Jul 16, 2020 5:26 am
Github: yukinogatari
Contact:

Re: FancyText: Effects for Slow Text Display

#10 Post by yukinogatari »

Good to know! I don't know a thing about writing shaders but I'll definitely have to play around with it if Ren'Py's getting some kind of custom shader support.

User avatar
XT9K
Newbie
Posts: 14
Joined: Sun Nov 01, 2020 10:50 pm
Contact:

Re: FancyText: Effects for Slow Text Display

#11 Post by XT9K »

I've implemented my own version of this if you'd like to check it out. viewtopic.php?f=51&t=60527 I even used your idea for help applying rotations to the renders, so really thankful for that!

Wizard Whithbrin
Newbie
Posts: 3
Joined: Thu Jun 03, 2021 8:26 pm
Contact:

Re: FancyText: Effects for Slow Text Display

#12 Post by Wizard Whithbrin »

Hey, pardon me. I've been experimenting with this script today and I noticed that it seems to completely break side images? (You know, character portraits in the text boxes?)

When the following code is present in the script:

Code: Select all

init -1:
    # FancyText: To use this say screen, you need to add the three parameters exactly as given!
    screen say(who, what, slow_effect = slow_typewriter, slow_effect_delay = 0, always_effect = None):
        style_prefix "say"

        window:
            id "window"

            if who is not None:

                window:
                    id "namebox"
                    style "namebox"
                    text who id "who"

            # FancyText: Here's where all the magic happens.
            # Replace your usual "text" statement with "fancytext" to enable
            # some fancy effects on text display.
            fancytext what id "what" slow_effect slow_effect slow_effect_delay slow_effect_delay always_effect always_effect
Update: This may have been because I added it separately. If anyone else ever has this issue, it can be fixed by adding

Code: Select all

                if not renpy.variant("small"):
                    add SideImage() xalign 0.0 yalign 1.0
from screens.rpy

User avatar
Wadanohara
Newbie
Posts: 2
Joined: Thu Mar 18, 2021 11:03 am
Completed: Horologium
Projects: Conglomerate, Iron Is Singing, Reverie, etc
Tumblr: sergeizemtsev
Soundcloud: sergei-zemtsev
itch: sergeizemtsev
Location: Krasnoyarsk, Russian Federation
Contact:

Re: FancyText: Effects for Slow Text Display

#13 Post by Wadanohara »

Many thanks for the module, it works just fine!

User avatar
Tayruu
Regular
Posts: 141
Joined: Sat Jul 05, 2014 7:57 pm

Re: FancyText: Effects for Slow Text Display

#14 Post by Tayruu »

This appears to be broken in the Ren'py 8.0.1 Python 3 and 7.5.1 Python 2 - it causes {w}ait tags and end-of-lines to require and extra click to dismiss. The first one finishes callbacks (ie. text-blip effects don't finish on wait-tags until you click once), then the second proceeds onto the next line.

User avatar
Waffle631
Newbie
Posts: 1
Joined: Wed Aug 17, 2022 12:08 pm
Contact:

Re: FancyText: Effects for Slow Text Display

#15 Post by Waffle631 »

To fix the problem whit the double click to dismiss change this line

Code: Select all

renpy.display.interface.timeout(0)
with this line

Code: Select all

self.call_slow_done(st)
That solve the issue if you use slow_effect, but the always effect still buggy.

Post Reply

Who is online

Users browsing this forum: No registered users