Attach animation to point gain/point loss

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
lindsay-jb
Regular
Posts: 68
Joined: Tue Aug 25, 2020 1:05 am
Contact:

Attach animation to point gain/point loss

#1 Post by lindsay-jb »

Is it possible to attach an animation to automatically play whenever you specify point gain/point loss? For example, I have relationship meters that change depending on your choices, and if the relationship goes down I'd like to add a little animation/displayable that says "[character] approves" or "[character] disapproves." But I'm not sure how I'd go about doing this. I know the other option would be to manually do it, but for easiness sake, I'd prefer if the animations would trigger automatically when I notate the point gains or loss.

User avatar
Alex
Lemma-Class Veteran
Posts: 3097
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Attach animation to point gain/point loss

#2 Post by Alex »

lindsay-jb wrote: Mon Oct 18, 2021 11:52 am Is it possible to attach an animation to automatically play whenever you specify point gain/point loss? ...
Try this - viewtopic.php?f=8&t=62204#p542910

lindsay-jb
Regular
Posts: 68
Joined: Tue Aug 25, 2020 1:05 am
Contact:

Re: Attach animation to point gain/point loss

#3 Post by lindsay-jb »

Awesome! That did mostly work, however I would like for the animation to dissolve in and move vertically up on the screen for about 1.0, and the transform doesn't seem to be doing anything. Here's what I have:

Code: Select all

    def my_func(txt, pos, t=4.0):
        renpy.show_screen("test_scr", my_txt=txt, txt_pos=pos, t=t)

    def check_func():
        global rowan_nerve, rowan_nerve_old, amalia_relationship, amalia_relationship_old, abel_relationship, abel_relationship_old, lincoln_relationship, lincoln_relationship_old, jocelyn_relationship, jocelyn_relationship_old
        if amalia_relationship > amalia_relationship_old:
            my_func("images/Nerve Icons/point gain.png", (0.25, 0.5), 0.5)
        if amalia_relationship < amalia_relationship_old:
            my_func("images/Nerve Icons/point loss.png", (0.25, 0.5), 0.5)
        if abel_relationship > abel_relationship_old:
            my_func("images/Nerve Icons/point gain.png", (0.25, 0.5), 0.5)
        if abel_relationship < abel_relationship_old:
            my_func("images/Nerve Icons/point loss.png", (0.25, 0.5), 0.5)
        if lincoln_relationship > lincoln_relationship_old:
            my_func("images/Nerve Icons/point gain.png", (0.25, 0.5), 0.5)
        if lincoln_relationship < lincoln_relationship_old:
            my_func("images/Nerve Icons/point loss.png", (0.25, 0.5), 0.5)
        if jocelyn_relationship > jocelyn_relationship_old:
            my_func("images/Nerve Icons/point gain.png", (0.25, 0.5), 0.5)
        if jocelyn_relationship < jocelyn_relationship_old:
            my_func("images/Nerve Icons/point loss.png", (0.25, 0.5), 0.5)

    config.python_callbacks.append(check_func)

transform my_transform(t=4.0):
    yalign 0.5
    linear 0.75 yalign 8.0

screen test_scr(my_txt, txt_pos, t):
    add my_txt align txt_pos
    timer 1.0 action Hide("test_scr", dissolve)

###relationships
default amalia_relationship = 30
default amalia_relationship_old = 30
default abel_relationship = 15
default abel_relationship_old = 15
default lincoln_relationship = 8
default lincoln_relationship_old = 8
default jocelyn_relationship = 2
default jocelyn_relationship_old = 2
I'm assuming I can manipulate the transform to move the icon up vertically, but I can't figure out how, because it doesn't seem to be affecting anything. In fact, I deleted that line of code to see if it would affect anything, and it didn't. Also, I'd like the icon to dissolve in rather than just appear, but I can only see how to dissolve it on hide. Anyway, any ideas on how to do that?

lindsay-jb
Regular
Posts: 68
Joined: Tue Aug 25, 2020 1:05 am
Contact:

Re: Attach animation to point gain/point loss

#4 Post by lindsay-jb »

I actually figured it out lol

I did this:

Code: Select all

transform my_transform(t=2.0):
    yalign 0.5
    linear 1.0 yalign 0.3

screen test_scr(my_txt, txt_pos, t):
    add my_txt align txt_pos at my_transform
    timer 0.6 action Hide("test_scr", dissolve)
And the icon moves just like I wanted!

lindsay-jb
Regular
Posts: 68
Joined: Tue Aug 25, 2020 1:05 am
Contact:

Re: Attach animation to point gain/point loss

#5 Post by lindsay-jb »

Okay, everything is working the way I want. However, I do have one more question for it to be perfect.

Is there a way to show how many points are being added or taken away? Because right now, I can only have it show if you're gaining or losing points. But what if they're losing 5 points, or just 1? Is there a way to show the amount that's actually being added?

User avatar
hell_oh_world
Miko-Class Veteran
Posts: 777
Joined: Fri Jul 12, 2019 5:21 am
Contact:

Re: Attach animation to point gain/point loss

#6 Post by hell_oh_world »

Just use other displayables probably.

Code: Select all

my_func(Fixed("images/Nerve Icons/point loss.png", Text(str(new - old)), fit_first=True), (0.25, 0.5), 0.5)

lindsay-jb
Regular
Posts: 68
Joined: Tue Aug 25, 2020 1:05 am
Contact:

Re: Attach animation to point gain/point loss

#7 Post by lindsay-jb »

Cool! That mostly worked, however I do have one small problem now. I'm not sure how to manipulate the plus/minus points text since it's not inside quotations marks and seen as text. I want to define its size, color, and make it bold. Here's what I have:

Code: Select all

init python:
    def my_func3(txt, txt1, txt2, pos, txt3):
        renpy.show_screen("test_scr3", my_txt=txt, my_txt1=txt1, my_txt2=txt2, txt2_pos=pos, my_txt3=txt3)

    def check_func3():
        global rowan_nerve, rowan_nerve_old
        if rowan_nerve > rowan_nerve_old:
            my_func3("images/Nerve Icons/point gain.png", "{color=#E5DBD9}{b}[capsRowan]+{/color}{/b}", "images/nerve gain.png", (768, 1360), Text(str(rowan_nerve - rowan_nerve_old)))
	....
	
        rowan_nerve_old = rowan_nerve

    config.python_callbacks.append(check_func3)

transform nerve_rowan_icon():
    xalign 0.68
    yalign 0.55
    linear 1.25 yalign 0.3

transform nerve_rowan():
    xalign 0.85
    yalign 0.56
    linear 1.25 yalign 0.31

transform my_transform3():
    xalign 0.91
    yalign 0.56
    linear 1.25 yalign 0.31

screen test_scr3(my_txt, my_txt1, my_txt2, txt2_pos, my_txt3):
    add my_txt at nerve_rowan_icon
    text my_txt1 size 25 at nerve_rowan
    add my_txt2 align txt2_pos
    text my_txt3 size 25 at my_transform3
    timer 0.9 action Hide("test_scr3", dissolve)

###
default rowan_nerve = 50
default rowan_nerve_old = 50
I want the my_txt3 to be the same size and color as my_txt1. Right now, it's dark gray instead of white and the default size, which is like 35 instead of 25 like I want. How can I do that?

User avatar
Alex
Lemma-Class Veteran
Posts: 3097
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Attach animation to point gain/point loss

#8 Post by Alex »

lindsay-jb wrote: Tue Oct 19, 2021 1:10 pm ...

Code: Select all

init python:
            my_func3("images/Nerve Icons/point gain.png", "{color=#E5DBD9}{b}[capsRowan]+{/color}{/b}", "images/nerve gain.png", (768, 1360), Text(str(rowan_nerve - rowan_nerve_old)))
...
Instead of

Code: Select all

Text(str(rowan_nerve - rowan_nerve_old))
try just

Code: Select all

str(rowan_nerve - rowan_nerve_old)
In hell_oh_world's sample function expects one value, so it get the fixed, that consist of an image and a text.
You've modified function, so it expects several values and you simply can give it a text value (converted to string result of subtraction).

lindsay-jb
Regular
Posts: 68
Joined: Tue Aug 25, 2020 1:05 am
Contact:

Re: Attach animation to point gain/point loss

#9 Post by lindsay-jb »

Thank you so much! Did this and it worked like a charm:

Code: Select all

    def check_func3():
        global rowan_nerve, rowan_nerve_old
        if rowan_nerve > rowan_nerve_old:
            my_func3("images/Nerve Icons/point gain.png", "{color=#E5DBD9}{b}[capsRowan]+{/color}{/b}", "images/nerve gain.png", (768, 1360), str(rowan_nerve - rowan_nerve_old))

...

screen test_scr3(my_txt, my_txt1, my_txt2, txt2_pos, my_txt3):
    add my_txt at nerve_rowan_icon
    text my_txt1 size 25 at nerve_rowan
    add my_txt2 align txt2_pos
    text my_txt3 size 25 color "#E5DBD9" bold True at my_transform3
    timer 0.9 action Hide("test_scr3", dissolve)

Post Reply

Who is online

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