Problem with button sliding animation [Solved]

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
rufiangel
Regular
Posts: 29
Joined: Sat Dec 01, 2012 5:45 am
Contact:

Problem with button sliding animation [Solved]

#1 Post by rufiangel »

Hi everyone, we are hard at work coding our game, but our coder has run into an issue that they would like some assistance on solving.

What we want to try is to create a button that you can click, that will then slide over to the other side of the screen, revealing a displayable that contains icons and/or stats. If you click the button again, it should slide all the way back and hide the displayable again.

He's written code that will do this once fairly perfectly based on what we are trying to do, but it unfortunately won't do it properly after the first time round. After we get the button to slide to the right, and then back to the left, it henceforth teleports to the coordinate after we click the button instead of sliding.

Code: Select all

init -2:

    transform slideRight:
        xpos -0.1
        linear 2.0 xpos 0.9
        #repeat

    transform slideLeft:
        xpos 0.9
        linear 2.0 xpos -0.1
        #repeat

    $ menuOpen = False

screen test:

    if menuOpen:
        imagebutton:
            idle "#000"
            hover "#00f"
            xysize(100,100)
            #xpos -0.1
            action SetVariable( "menuOpen", (True if menuOpen == False else False) ) at slideLeft
    elif not menuOpen:
        imagebutton:
            idle "#000"
            hover "#00f"
            xysize(100,100)
            #xpos 0.9
            action SetVariable( "menuOpen", (True if menuOpen == False else False) ) at slideRight
He is scratching his head over this and I am not a coder by any means, so we'd really appreciate any insight into what might be causing the issue. If anyone has any suggestions on how to achieve the same effect through different code, please also feel free to chime in.

We are grateful for any assistance, thank you! >3<*
Last edited by rufiangel on Mon Oct 11, 2021 8:15 am, edited 1 time in total.
Please check out Speechless, a project on hold for the moment!
Serpamia Flare: http://www.serpamiaflare.com
The Lethian: http://www.thelethian.com
DeviantArt: http://rufiangel.deviantart.com

jeffster
Veteran
Posts: 409
Joined: Wed Feb 03, 2021 9:55 pm
Contact:

Re: Problem with button sliding animation

#2 Post by jeffster »

I would advise to use

Code: Select all

action ToggleVariable("menuOpen")
instead of

Code: Select all

SetVariable( "menuOpen", (True if menuOpen == False else False) )
and put "at slideLeft" / "at slideRight" on separate lines.
And use non-negative xpos.
Anyways, your example works well on my computer, sliding forth and back, so I don't see any issue:

Code: Select all

init -2:

    transform slideRight:
        xpos 0.1
        linear 2.0 xpos 0.9

    transform slideLeft:
        xpos 0.9
        linear 2.0 xpos 0.1

    $ menuOpen = False

screen test:

    if menuOpen:
        imagebutton:
            idle "#0F0"
            hover "#00F"
            xysize(100,100)
            action ToggleVariable("menuOpen")
            at slideLeft
    elif not menuOpen:
        imagebutton:
            idle "#F00"
            hover "#00F"
            xysize(100,100)
            action ToggleVariable("menuOpen")
            at slideRight

label main_menu:
    return

label start:
    "Start"
    call screen test
    "End"
Another way to do that would be to wrap the button as "drag" and when necessary use snap function, as that moves drags (only in a linear motion, but that's exactly what you use).

https://www.renpy.org/doc/html/drag_drop.html#Drag.snap

rufiangel
Regular
Posts: 29
Joined: Sat Dec 01, 2012 5:45 am
Contact:

Re: Problem with button sliding animation

#3 Post by rufiangel »

Thank you jeffster for taking the time to look at the code and provide a response! :)

The issue unfortunately continues to persist despite the adjustments to our code, which is that when you click the button once to go right, and then once to go left, it works only the first time around. After that, it teleports instead of sliding. We are wondering if it is possible to actually make the effect happen more than once.

Appreciate you suggesting drag/snap, we'll look into it as well. Thanks!
Please check out Speechless, a project on hold for the moment!
Serpamia Flare: http://www.serpamiaflare.com
The Lethian: http://www.thelethian.com
DeviantArt: http://rufiangel.deviantart.com

jeffster
Veteran
Posts: 409
Joined: Wed Feb 03, 2021 9:55 pm
Contact:

Re: Problem with button sliding animation

#4 Post by jeffster »

rufiangel, did you try to use my code as script.rpy in an empty project, without any other code there? If it works (it should) it means the problem is caused by some other piece of your code. Or, I don't know, make sure you use the latest Ren'Py version. Also delete all files in game/cache folder to make Ren'Py recompile everything from scratch.

rufiangel
Regular
Posts: 29
Joined: Sat Dec 01, 2012 5:45 am
Contact:

Re: Problem with button sliding animation

#5 Post by rufiangel »

The issue is fixed now! :) Thanks jeffster very much for your assistance!
Please check out Speechless, a project on hold for the moment!
Serpamia Flare: http://www.serpamiaflare.com
The Lethian: http://www.thelethian.com
DeviantArt: http://rufiangel.deviantart.com

Post Reply

Who is online

Users browsing this forum: No registered users