[solved] Using videos as button?

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
Kia
Eileen-Class Veteran
Posts: 1040
Joined: Fri Aug 01, 2014 7:49 am
Deviantart: KiaAzad
Discord: Kia#6810
Contact:

[solved] Using videos as button?

#1 Post by Kia »

I'm trying to use two videos for hover and idle states of a button. The normal route of using them as `background` and `hover_background` will cause them reset when the button is hovered.
As a workaround I've tried:

Code: Select all

screen video_test_screen:
    default over = 0
    add "video_idle"
    add "video_hover" at video_alpha(over)
    button:
        align (0.5, 0.5) background "#333" hover_background "#192"
        text "test"
        hovered SetScreenVariable("over", 1)
        unhovered SetScreenVariable("over", 0)
        action NullAction()
But looks like when two videos are played over each other, the top video stays visible despite it's alpha transform.
I wonder if anybody ever tried doing this and got something working?
Last edited by Kia on Thu Mar 28, 2024 2:06 am, edited 1 time in total.

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2405
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Using videos as button?

#2 Post by Ocelot »

Interesting. Defining videos as

Code: Select all

image video_idle:
    animation
    Movie(play="images/MOV_Achenar_Page_00.mp4")
and using them as background/hover_background works with a single caveat: hover video is only started when button is hovered for the first time. Then it is played uninterrupted as intended. It won't work if you want to synchronize both videos, but if the only goal is to not restart animations each time, then it works. I alsotried using idle_child / hover_child in hope that it will keep animation timebase, but it seems that the problem lies in the fact that movies are not started until shown.
< < insert Rick Cook quote here > >

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2405
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Using videos as button?

#3 Post by Ocelot »

A modified version of your approach seems to work:

Code: Select all

screen video_test_screen:
    default ap = 0.0
    button:
        action NullAction()
        hovered SetScreenVariable("ap", 1)
        unhovered SetScreenVariable("ap", 0)
        has fixed
        fit_first True
        add "video idle"
        add "video hover":
            alpha ap
< < insert Rick Cook quote here > >

User avatar
Kia
Eileen-Class Veteran
Posts: 1040
Joined: Fri Aug 01, 2014 7:49 am
Deviantart: KiaAzad
Discord: Kia#6810
Contact:

Re: Using videos as button?

#4 Post by Kia »

Thank you Ocelot, it works like a charm.
We have `side_mask` that ensures the video and its mask stay in sync, I imagine if we could do another split, we can fit two videos and two masks in the same video file, to use in buttons and such. But there aren't that many developers that are looking for a functionality like that.

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3794
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: [solved] Using videos as button?

#5 Post by Imperf3kt »

I personally would have just created a frame displaying the video, then placed an invisible button over top of that. With a little tweaking, this is also an option.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

User avatar
Kia
Eileen-Class Veteran
Posts: 1040
Joined: Fri Aug 01, 2014 7:49 am
Deviantart: KiaAzad
Discord: Kia#6810
Contact:

Re: [solved] Using videos as button?

#6 Post by Kia »

Imperf3kt wrote: Thu Mar 28, 2024 2:26 am I personally would have just created a frame displaying the video, then placed an invisible button over top of that. With a little tweaking, this is also an option.
My test was kind of the same, but for some reason, two videos placed over each other causes some odd behaviors, when it comes to applying a transform to one of them.

Post Reply

Who is online

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