Modifying image Gallery for use with movies

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
umineko
Regular
Posts: 52
Joined: Sun Jan 09, 2022 7:12 am
Projects: Ikimashou!
Organization: Bagel Poutine
itch: umineko-chan.itch.io
Contact:

Modifying image Gallery for use with movies

#1 Post by umineko »

Hey, all! I recently used the image/cg gallery function for use with videos. https://www.renpy.org/doc/html/rooms.html

Code: Select all

    g_video = Gallery()
    g_video.button("bagelpoutine")
    g_video.image("bagelpoutine")
    
    g_video.button("opening")
    g_video.image("opening")

Code: Select all

image bagelpoutine = Movie(size=(1920, 1080), play="movie/bagelpoutine.webm")
image opening = Movie(size=(1920, 1080), play="movie/opening.webm")
screen video_gallery():

    tag menu
    ## This use statement includes the extras_menu screen inside this one.
    use extras_menu("Videos"):

        vpgrid:

            cols 2
            spacing 23
            draggable True
            mousewheel True
            xfill False
            yfill False
            scrollbars "vertical"
            right_margin 60
            ypos 4
            xpos 100
            ## Call make_button to show a particular button.
            # add g_video.make_button("background", "bg_button")
            add g_video.make_button("bagelpoutine", "montreal1_button", xalign=0.5, yalign=0.5, hover_border="gui/button/bg_gallery/button1_h.png")
            add g_video.make_button("opening", "windsorstation_button", xalign=0.5, yalign=0.5, hover_border="gui/button/bg_gallery/button2_h.png")
The buttons will play the video as usual, but I want to find a way to mute the music/all other sounds whenever a movie is playing, since it has it's own music. Perhaps, is there a way to do that, or run functions whenever a button is clicked? Thanks in advance!
"I like kemomimi and I cannot lie."

User avatar
plastiekk
Regular
Posts: 112
Joined: Wed Sep 29, 2021 4:08 am
Contact:

Re: Modifying image Gallery for use with movies

#2 Post by plastiekk »

umineko wrote: Mon Oct 10, 2022 11:44 pm The buttons will play the video as usual, but I want to find a way to mute the music/all other sounds whenever a movie is playing, since it has it's own music. Perhaps, is there a way to do that, or run functions whenever a button is clicked?
I don't know how your buttons are created but the action you want to add should look like this:

Code: Select all

action Function (renpy.music.stop, fadeout= 0.5)
Another options is to add the stop music action to your video_gallery screen.

Code: Select all

screen video_gallery():

    timer 0.01 repeat False action Function (renpy.music.stop, fadeout= 0.5)   # fadeout music on channel music
    tag menu
    ## This use statement includes the extras_menu screen inside this one.
    use extras_menu("Videos"):

        vpgrid:

            cols 2
            spacing 23
            ...
Why on earth did I put the bread in the fridge?

User avatar
umineko
Regular
Posts: 52
Joined: Sun Jan 09, 2022 7:12 am
Projects: Ikimashou!
Organization: Bagel Poutine
itch: umineko-chan.itch.io
Contact:

Re: Modifying image Gallery for use with movies

#3 Post by umineko »

Hi, I found the gallery function built into renpy. The code is in the attachments, although I have no idea how to edit it for movies.
00gallery.rpy
(18.22 KiB) Downloaded 16 times
plastiekk wrote: Thu Oct 20, 2022 10:12 am
umineko wrote: Mon Oct 10, 2022 11:44 pm The buttons will play the video as usual, but I want to find a way to mute the music/all other sounds whenever a movie is playing, since it has it's own music. Perhaps, is there a way to do that, or run functions whenever a button is clicked?
I don't know how your buttons are created but the action you want to add should look like this:

Code: Select all

action Function (renpy.music.stop, fadeout= 0.5)
Another options is to add the stop music action to your video_gallery screen.

Code: Select all

screen video_gallery():

    timer 0.01 repeat False action Function (renpy.music.stop, fadeout= 0.5)   # fadeout music on channel music
    tag menu
    ## This use statement includes the extras_menu screen inside this one.
    use extras_menu("Videos"):

        vpgrid:

            cols 2
            spacing 23
            ...
Regarding your solution, it works well, but I'm not able to get the music playing again once the player leaves the screen. The "replaced" action works, but it can be bypassed if the player clicks twice or more times on the video gallery button.
"I like kemomimi and I cannot lie."

User avatar
plastiekk
Regular
Posts: 112
Joined: Wed Sep 29, 2021 4:08 am
Contact:

Re: Modifying image Gallery for use with movies

#4 Post by plastiekk »

EDIT: I forgot to insert a quote and it works also with a playlist but will reset every time you visited the video gallery
umineko wrote: Tue Oct 25, 2022 4:55 am Regarding your solution, it works well, but I'm not able to get the music playing again once the player leaves the screen.


Hi there, we should better not touch the 00gallery.rpy because it's also doable with normal screens.

Here's my solution wich works under the following conditions:
1. I assume that you play only one music file and use the defined Ren'Py Menus/Screens.
2. You want to hear the music during the whole game, also in the menus.
3. You want to turn it off in the video gallery and play it again when you leave the menu.

My procedure is as follows: We write a function that determines whether music is played and if not then plays it. We call this function in the navigation bar of the menu, so we make sure that it is turned on again as soon as the video gallery is left.

This function goes into your script.rpy

Code: Select all

# The script of the game goes in this file.

# This function will check if a music is played and turn it on if not.
init python:
    def sound_check():
        if renpy.music.is_playing(channel=u'music')== False:
            renpy.music.play(config.main_menu_music, fadein=0.5, loop=True) # no need to edit the audio files twice. we just use the var
        return 

# Set an audio file that will be played while
# the player is at the main menu. This file will continue playing into the
# game, until it is stopped or another file is played.    

define config.main_menu_music = "audio/ost.mp3"	### a single audio file
# define config.main_menu_music = ["audio/ost.mp3","audio/score.wav","disco.mp3"]  ### a playlist

Next step is to insert the function call in the screens.rpy
We use the screen_navigation(): You'll find it in Line 288

Code: Select all

timer 0.01 repeat False action Function(sound_check)
It should look like this:

Code: Select all

screen navigation():
    timer 0.01 repeat False action Function(sound_check)
    vbox:
        style_prefix "navigation"

        xpos gui.navigation_xpos
        ...
That's it.
Hope it helps!

p.s. leave your screen video_gallery like before.

Code: Select all

screen video_gallery():

    timer 0.01 repeat False action Function (renpy.music.stop, fadeout= 0.5)   # fadeout music on channel music
    tag menu
    ## This use statement includes the extras_menu screen inside this one.
    use extras_menu("Videos"):

        vpgrid:

            cols 2
            spacing 23
            ...
Last edited by plastiekk on Wed Oct 26, 2022 10:41 am, edited 1 time in total.
Why on earth did I put the bread in the fridge?

User avatar
plastiekk
Regular
Posts: 112
Joined: Wed Sep 29, 2021 4:08 am
Contact:

Re: Modifying image Gallery for use with movies

#5 Post by plastiekk »

umineko wrote: Tue Oct 25, 2022 4:55 am ...
I have edited my post above.
Why on earth did I put the bread in the fridge?

User avatar
umineko
Regular
Posts: 52
Joined: Sun Jan 09, 2022 7:12 am
Projects: Ikimashou!
Organization: Bagel Poutine
itch: umineko-chan.itch.io
Contact:

Re: Modifying image Gallery for use with movies

#6 Post by umineko »

plastiekk wrote: Tue Oct 25, 2022 9:01 am EDIT: I forgot to insert a quote and it works also with a playlist but will reset every time you visited the video gallery
umineko wrote: Tue Oct 25, 2022 4:55 am Regarding your solution, it works well, but I'm not able to get the music playing again once the player leaves the screen.


Hi there, we should better not touch the 00gallery.rpy because it's also doable with normal screens.

Here's my solution wich works under the following conditions:
1. I assume that you play only one music file and use the defined Ren'Py Menus/Screens.
2. You want to hear the music during the whole game, also in the menus.
3. You want to turn it off in the video gallery and play it again when you leave the menu.

My procedure is as follows: We write a function that determines whether music is played and if not then plays it. We call this function in the navigation bar of the menu, so we make sure that it is turned on again as soon as the video gallery is left.

This function goes into your script.rpy

Code: Select all

# The script of the game goes in this file.

# This function will check if a music is played and turn it on if not.
init python:
    def sound_check():
        if renpy.music.is_playing(channel=u'music')== False:
            renpy.music.play(config.main_menu_music, fadein=0.5, loop=True) # no need to edit the audio files twice. we just use the var
        return 

# Set an audio file that will be played while
# the player is at the main menu. This file will continue playing into the
# game, until it is stopped or another file is played.    

define config.main_menu_music = "audio/ost.mp3"	### a single audio file
# define config.main_menu_music = ["audio/ost.mp3","audio/score.wav","disco.mp3"]  ### a playlist

Next step is to insert the function call in the screens.rpy
We use the screen_navigation(): You'll find it in Line 288

Code: Select all

timer 0.01 repeat False action Function(sound_check)
It should look like this:

Code: Select all

screen navigation():
    timer 0.01 repeat False action Function(sound_check)
    vbox:
        style_prefix "navigation"

        xpos gui.navigation_xpos
        ...
That's it.
Hope it helps!

p.s. leave your screen video_gallery like before.

Code: Select all

screen video_gallery():

    timer 0.01 repeat False action Function (renpy.music.stop, fadeout= 0.5)   # fadeout music on channel music
    tag menu
    ## This use statement includes the extras_menu screen inside this one.
    use extras_menu("Videos"):

        vpgrid:

            cols 2
            spacing 23
            ...
Added an example, create a new project and insert these files there to see how it works. I have not included music, you have to insert it yourself and edit filenames in the script.rpy.
That worked, thanks a lot for your help :D
"I like kemomimi and I cannot lie."

User avatar
plastiekk
Regular
Posts: 112
Joined: Wed Sep 29, 2021 4:08 am
Contact:

Re: Modifying image Gallery for use with movies

#7 Post by plastiekk »

umineko wrote: Wed Oct 26, 2022 2:29 am That worked, thanks a lot for your help :D
You're welcome. But to be honest, I think that a permanent loop is very annoying after a while, so I wouldn't want to use this method in my game unless I have a really epic music. :)
Why on earth did I put the bread in the fridge?

Post Reply

Who is online

Users browsing this forum: Amazon [Bot]