FancyText is a
Click the image below to see a quick sample of what FancyText is capable of doing.
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.
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.
- 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.
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.5). 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.