Fading onscreen text

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.
Post Reply
Message
Author
User avatar
Zetsubou
Miko-Class Veteran
Posts: 522
Joined: Wed Mar 05, 2014 1:00 am
Completed: See my signature
Github: koroshiya
itch: zetsuboushita
Contact:

Fading onscreen text

#1 Post by Zetsubou »

I'll see about making a short video to show off the effect, but for the time being the definition is:

Code: Select all

init python:
    def fadingText(text, xpos=100, ypos=100, size=24, moveX=0, moveY=0, color="#fff"):
        for i in xrange(0, 16):
            curX = "%x" % (15 - i)
            ui.text("{color="+color+curX+"}"+text+"{/color}", xpos=(xpos + moveX * i), ypos=(ypos + moveY * i), size=size)

            renpy.pause(1/60)
which is then called from your renpy script by something like:

Code: Select all

$ fadingText("sniff", 400, 300, 24, -2, 1)
In the above example the text "sniff" appears at 400x300 in size 24, then moves 2 to the left and down 1 every iteration (30 left, 15 down total).
The color is unchanged, and thus defaults to white.

This isn't anything too flashy or complicated. It's just text that appears on screen and quickly fades away.
For example, you could use it to show sound effects on screen, either for added effect or in case the player has their sound turned off.

Parameters:
text: the text to be displayed
xpos: the x position at which the text should initially be displayed
ypos: the y position at which the text should initially be displayed
size: the size of the text
moveX: how far to move the text along the X axis each iteration. Negative numbers move left, positive move right. Total movement = 15 x moveX.
moveY: how far to move the text along the Y axis each iteration. Negative numbers move up, positive move down. Total movement = 15 x moveY.
color: color of the text to display
Finished games
-My games: Sickness, Wander No More, Max Massacre, Humanity Must Perish, Tomboys Need Love Too, Sable's Grimoire, My Heart Grows Fonder, Man And Elf, A Dragon's Treasure, An Adventurer's Gallantry
-Commissions: No One But You, Written In The Sky, Diamond Rose, To Libertad, Catch Canvas, Love Ribbon, Happy Campers, Wolf Tails

Working on:
Sable's Grimoire 2

https://zetsubou.games

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

Re: Fading onscreen text

#2 Post by xela »

How the hell is this cookbook material? It's a "how I should never do this" guide...

Please read:

ATL

and glance over the rest of Ren'Py documentation before posting recipes that will just confuse and misinform newcomers.
Like what we're doing? Support us at:
Image

User avatar
Zetsubou
Miko-Class Veteran
Posts: 522
Joined: Wed Mar 05, 2014 1:00 am
Completed: See my signature
Github: koroshiya
itch: zetsuboushita
Contact:

Re: Fading onscreen text

#3 Post by Zetsubou »

If you have a good ATL way to do it, I'm all ears.
The only ATL methods I've found that will do the same all involve actual images or predefined text displayables, not dynamically inserted text.
Finished games
-My games: Sickness, Wander No More, Max Massacre, Humanity Must Perish, Tomboys Need Love Too, Sable's Grimoire, My Heart Grows Fonder, Man And Elf, A Dragon's Treasure, An Adventurer's Gallantry
-Commissions: No One But You, Written In The Sky, Diamond Rose, To Libertad, Catch Canvas, Love Ribbon, Happy Campers, Wolf Tails

Working on:
Sable's Grimoire 2

https://zetsubou.games

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

Re: Fading onscreen text

#4 Post by xela »

Zetsubou wrote:If you have a good ATL way to do it, I'm all ears.
The only ATL methods I've found that will do the same all involve actual images or predefined text displayables, not dynamically inserted text.
"Actual images" are displayable at well, if they're images you can apply image manipulators to them in addition to everything else Ren'Py has to offer.

Code: Select all

init python:
    def fading_text(text, t, x, y, move_x, move_y, *args, **kwargs):
        ui.add(At(Text(text, *args, **kwargs), fade_move_with_pars(t, x, y, move_x, move_y)))
            
transform fade_move_with_pars(t, x, y, move_x, move_y):
    parallel:
        alpha 1.0
        linear t alpha 0
    parallel:
        pos (x, y)
        linear t pos (move_x, move_y)

label start:
    $ fading_text("sniff", 1.0, 400, 300, 600, 600, color="#fff", size=24)
Function is not really needed but I am not sure what you've meant with "dynamically inserted text".

Note that 1/60 == 0 unless you convert something to float. (1.0/60) or import future division.

*This should be a screen btw, not another poor example of using ancient ui module, I just coded it to work similarly to your example.

Code: Select all

screen fading_text(text, t, x, y, move_x, move_y, *args, **kwargs):
        add Text(text, *args, **kwargs) at fade_move_with_pars(t, x, y, move_x, move_y)

label start:
    show screen fading_text("sniff", 3.0, 400, 300, 600, 600, color="#fff", size=24)
Like what we're doing? Support us at:
Image

User avatar
Zetsubou
Miko-Class Veteran
Posts: 522
Joined: Wed Mar 05, 2014 1:00 am
Completed: See my signature
Github: koroshiya
itch: zetsuboushita
Contact:

Re: Fading onscreen text

#5 Post by Zetsubou »

xela wrote:

Code: Select all

init python:
    def fading_text(text, t, x, y, move_x, move_y, *args, **kwargs):
        ui.add(At(Text(text, *args, **kwargs), fade_move_with_pars(t, x, y, move_x, move_y)))
            
transform fade_move_with_pars(t, x, y, move_x, move_y):
    parallel:
        alpha 1.0
        linear t alpha 0
    parallel:
        pos (x, y)
        linear t pos (move_x, move_y)

label start:
    $ fading_text("sniff", 1.0, 400, 300, 600, 600, color="#fff", size=24)
Nice. That's the kind of effect/simplicity I was aiming for :)
Finished games
-My games: Sickness, Wander No More, Max Massacre, Humanity Must Perish, Tomboys Need Love Too, Sable's Grimoire, My Heart Grows Fonder, Man And Elf, A Dragon's Treasure, An Adventurer's Gallantry
-Commissions: No One But You, Written In The Sky, Diamond Rose, To Libertad, Catch Canvas, Love Ribbon, Happy Campers, Wolf Tails

Working on:
Sable's Grimoire 2

https://zetsubou.games

Post Reply

Who is online

Users browsing this forum: No registered users