[Solved] Textbox animations, but specifically when a character changes

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
filthsama
Newbie
Posts: 18
Joined: Tue Jan 05, 2021 4:11 am
Completed: 0
Projects: A dating sim with some Persona mechanics
Contact:

[Solved] Textbox animations, but specifically when a character changes

#1 Post by filthsama »

I know how to animate a textbox so it plays every time you click, but the problem is that I want the textbox to only move either when a new character shows up or when the scene changes. The specific animation I want is the textbox to pop up from the bottom when it shows up, and for it to move down when it has to hide.

I tried using this, but I can't get the textbox to pop up again after starting the game, even if I use "window hide" and "window show"

Code: Select all

init python:
    def say_window_transform(trans, st, at):
        global say_window_show_transform

        if not "say_window_show_transform" in globals():
            say_window_show_transform = False

        if say_window_show_transform == False:
            trans.yoffset = 250
            say_window_show_transform = True

        if say_window_show_transform == True:
            if st > 0.5:
                trans.yoffset = 0
                return None
            else:
                trans.yoffset -= trans.yoffset * st
                return 0
        else:
            return None

    def say_window_transform_reset(trans, st, at):
        global say_window_show_transform
        say_window_show_transform = False

transform say_window_animation:
    on show:
        function say_window_transform
    on hide:
        yoffset 0
        linear 0.3 yoffset 250
        function say_window_tranform_reset

transform text_fade_in:
    alpha 0
    linear 0.5 alpha 1
I'm a bit of a newbie, and I can't properly read python, so apologies if the problem was extremely simple. I had taken it directly from another post.
Last edited by filthsama on Wed Aug 04, 2021 9:07 pm, edited 1 time in total.

User avatar
zmook
Veteran
Posts: 421
Joined: Wed Aug 26, 2020 6:44 pm
Contact:

Re: Textbox animations, but specifically when a character changes

#2 Post by zmook »

It looks like your problem is a typo where you have "function say_window_tranform_reset" instead of "function say_window_transform_reset". Though, that should throw an error and you didn't mention one.

You also need to have

Code: Select all

    window:
        at say_window_animation
        id "window"
in your say screen, but it won't work at all without that, if I understand you right it does work the first time.

Do either of those fix your problem?
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM

User avatar
filthsama
Newbie
Posts: 18
Joined: Tue Jan 05, 2021 4:11 am
Completed: 0
Projects: A dating sim with some Persona mechanics
Contact:

Re: Textbox animations, but specifically when a character changes

#3 Post by filthsama »

zmook wrote: Sun Mar 21, 2021 12:33 pm It looks like your problem is a typo where you have "function say_window_tranform_reset" instead of "function say_window_transform_reset". Though, that should throw an error and you didn't mention one.

You also need to have

Code: Select all

    window:
        at say_window_animation
        id "window"
in your say screen, but it won't work at all without that, if I understand you right it does work the first time.

Do either of those fix your problem?
My bad, I didn't include the fixed typo or the window code on there. I already had both, but it just seems the effect itself doesn't do what I specifically want. It seems to only pop up at the very beginning of my game. After that, it defaults to a Dissolve effect (which I fiddled around and set the default window hide/show animation to None, but that didn't help at all.)

User avatar
filthsama
Newbie
Posts: 18
Joined: Tue Jan 05, 2021 4:11 am
Completed: 0
Projects: A dating sim with some Persona mechanics
Contact:

Re: Textbox animations, but specifically when a character changes

#4 Post by filthsama »

Slight update. So I think I figured out the problem is, but I'm not sure how to fix it. Here's a repost of the code (fixed for typos and such):

Code: Select all

init python:
    def say_window_transform(trans, st, at):
        global say_window_show_transform

        if not "say_window_show_transform" in globals():
            say_window_show_transform = False

        if say_window_show_transform == False:
            trans.yoffset = 250
            say_window_show_transform = True

        if say_window_show_transform == True:
            if st > 0.5:
                trans.yoffset = 0
                return None
            else:
                trans.yoffset -= trans.yoffset * st
                return 0
        else:
            return None

    def say_window_transform_reset(trans, st, at):
        global say_window_show_transform
        say_window_show_transform = False

transform say_window_animation:
    on show:
        function say_window_transform
    on hide:
    	yoffset 0
        linear 0.3 yoffset 250
        function say_window_transform_reset     
And then this in screens.rpy:

Code: Select all

screen say(who, what):
    style_prefix "say"

    window:
        at say_window_animation
        id "window"

        if who is not None:

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

        text what id "what" at text_fade_in
I figured out the issue here is the "on hide" command since what I assume the code is supposed to do is reset the window showing animation whenever I write "window hide", but clearly that isn't working. All it does is go to the default Dissolve that is on config.window_hide_transition. I have asked around and I guess "on hide" just doesn't work here. Any ways to replace that? I'm gonna go crazy if I can't figure out this textbox.

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: Textbox animations, but specifically when a character changes

#5 Post by Remix »

Transient screens do not recognize the hide event so will not play nicely with transforms like that.

One approach might be to use show_layer_at to affect an entire layer...
(this example plops the say screen on a new layer so as not to bork other screens)

Code: Select all

init python:
    renpy.add_layer(layer='say_screen', above="screens", menu_clear=True)
    config.say_layer = "say_screen"

transform retract():
    yoffset 0
    linear 2.0 yoffset 400

## yup, adjust as wanted and add an expand or whatever transform to bring it back...

label start:

    scene expression '#CCC'

    "words"
    $ renpy.show_layer_at(at_list=[retract], layer='say_screen')
    pause
Frameworks & Scriptlets:

User avatar
filthsama
Newbie
Posts: 18
Joined: Tue Jan 05, 2021 4:11 am
Completed: 0
Projects: A dating sim with some Persona mechanics
Contact:

Re: Textbox animations, but specifically when a character changes

#6 Post by filthsama »

Remix wrote: Wed Apr 14, 2021 6:37 pm Transient screens do not recognize the hide event so will not play nicely with transforms like that.

One approach might be to use show_layer_at to affect an entire layer...
(this example plops the say screen on a new layer so as not to bork other screens)

Code: Select all

init python:
    renpy.add_layer(layer='say_screen', above="screens", menu_clear=True)
    config.say_layer = "say_screen"

transform retract():
    yoffset 0
    linear 2.0 yoffset 400

## yup, adjust as wanted and add an expand or whatever transform to bring it back...

label start:

    scene expression '#CCC'

    "words"
    $ renpy.show_layer_at(at_list=[retract], layer='say_screen')
    pause
Thank you so much, this works great. If it's not too greedy to ask, would it be possible to optimize this even further? Implementing this seems to work like this:

Code: Select all

label start:
    scene one
    "words"
    $ renpy.show_layer_at(at_list=[retract], layer='say_screen')
    $ renpy.show_layer_at(at_list=[expand], layer='say_screen')
    "more words"
    "hahaha"
    "wow"
    $ renpy.show_layer_at(at_list=[retract], layer='say_screen')
    $ renpy.show_layer_at(at_list=[expand], layer='say_screen')
    "end"
    pause
I have to write two lines of code just for this to work. It's not the worst thing in the world, and I'd rather have it than nothing. But if possible, one line would be beautiful or, most preferably, changing automatically when a different character begins to speak or when I use "window hide". I assume "last_say_who" would be where to start, but I can't fathom how to make that work.

Thank you once again, sorry for asking for so much.

uncoded
Regular
Posts: 27
Joined: Fri Apr 09, 2021 10:29 am
Contact:

Re: Textbox animations, but specifically when a character changes

#7 Post by uncoded »

filthsama wrote: Wed Apr 14, 2021 6:58 pmI have to write two lines of code just for this to work. It's not the worst thing in the world, and I'd rather have it than nothing. But if possible, one line would be beautiful ...

Code: Select all

python:
    def your_beautiful_one_liner(layer='say_screen'):
        renpy.show_layer_at(at_list=[retract], layer)
        renpy.show_layer_at(at_list=[expand], layer)
Than just call this function in place of your two outrageous lines ? ;)
filthsama wrote: Wed Apr 14, 2021 6:58 pm... or, most preferably, changing automatically when a different character begins to speak or when I use "window hide". I assume "last_say_who" would be where to start, but I can't fathom how to make that work.
Maybe use a character callback ?
You might want to append your callback to config.all_character_callbacks, too.
🐾

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot]