[SOLVED] Sounds for image gallery buttons

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
chesarty
Regular
Posts: 116
Joined: Sat Aug 25, 2018 3:07 am
Completed: 0
Contact:

[SOLVED] Sounds for image gallery buttons

#1 Post by chesarty »

I want every button in my game to have the same hover and activation sounds, but I can't figure out how to do it in my image gallery :0

Here's my gallery code:

Code: Select all

init python:

   # Step 1. Create the gallery object.
    g = Gallery()

    g.locked_button = "images/gallery/locked.png" #this is the thumbnail image for ALL LOCKED gallery previews, found in the images folder
    
       # Step 2. Add buttons and images to the gallery.

   # A button that contains an image that automatically unlocks.
    g.button("g_01")        
    g.condition("persistent.unlock_1") 
    g.image("images/gallery/g_01.png") 
    
    g.button("g_02")
    g.condition("persistent.unlock_1")
    g.image("images/gallery/g_02.png")
        
    g.button("g_03")
    g.condition("persistent.unlock_1")
    g.image("images/gallery/g_03.png")
        
    g.button("g_04")
    g.condition("persistent.unlock_1")
    g.image("images/gallery/g_04.png")
    
    g.button("g_05")
    g.condition("persistent.unlock_1")
    g.image("images/gallery/g_05.png")
        
    g.button("g_06")
    g.condition("persistent.unlock_1")
    g.image("images/gallery/g_06.png")
        
    g.button("g_07")
    g.condition("persistent.unlock_2")
    g.image("images/gallery/g_07.png")
    
    g.button("g_08")
    g.condition("persistent.unlock_1")
    g.image("images/gallery/g_08.png")
        
    g.button("g_09")
    g.condition("persistent.unlock_1")
    g.image("images/gallery/g_09.png")
        
    g.button("g_10")
    g.condition("persistent.unlock_1")
    g.image("images/gallery/g_10.png")
    
    g.button("g_11")
    g.condition("persistent.unlock_1")
    g.image("images/gallery/g_11.png")
        
    g.button("g_12")
    g.condition("persistent.unlock_1")
    g.image("images/gallery/g_12.png")
    
    g.transition = Dissolve(0.2)
    

    
screen image_gallery:

   # Ensure this replaces the main menu.
    tag menu

   # The background.
    add "images/gallery/bg.png"
    
    # A grid of buttons.
    grid 4 3:

        xfill True
        yfill True
        

        # Call make_button to show a particular button.
        add g.make_button("g_01", "images/gallery/1.png", xalign=0.5, yalign=0.5)
        add g.make_button("g_02", "images/gallery/2.png", xalign=0.5, yalign=0.5)
        add g.make_button("g_03", "images/gallery/3.png", xalign=0.5, yalign=0.5)
        add g.make_button("g_04", "images/gallery/4.png", xalign=0.5, yalign=0.5)
        add g.make_button("g_05", "images/gallery/5.png", xalign=0.5, yalign=0.5)
        add g.make_button("g_06", "images/gallery/6.png", xalign=0.5, yalign=0.5)
        add g.make_button("g_07", "images/gallery/7.png", xalign=0.5, yalign=0.5)
        add g.make_button("g_08", "images/gallery/8.png", xalign=0.5, yalign=0.5)
        add g.make_button("g_09", "images/gallery/9.png", xalign=0.5, yalign=0.5)
        add g.make_button("g_10", "images/gallery/10.png", xalign=0.5, yalign=0.5)
        add g.make_button("g_11", "images/gallery/11.png", xalign=0.5, yalign=0.5)
        add g.make_button("g_12", "images/gallery/12.png", xalign=0.5, yalign=0.5)

    imagemap:
        
        idle "gui/d_profile_idle.png"
        hover "gui/d_profile_hover.png"
        
        hotspot (881, 982, 191, 52) action Return():
            hover_sound "audio/hoversound.mp3"
            activate_sound "audio/choicesound.mp3"
At the bottom with the hotspot there for the return imagebutton, you can see the sounds I want. I can't seem to be able to place them anywhere in the gallery button code, though...
Last edited by chesarty on Sun Oct 18, 2020 3:54 pm, edited 1 time in total.

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: Sounds for image gallery buttons

#2 Post by Remix »

make_button() allows a style=style_name property and passes through **kwargs to Button so you could either pass a named style and add the hover_sound and activate_sound to that (likely best as you could also put your aligns there) or pass them as keyword arguments...

Code: Select all

style gallery_button is empty:
    align (0.5, 0.5)
    hover_sound "audio/hoversound.mp3"
    activate_sound "audio/choicesound.mp3"
    ## might need more style setting or inherit from something else

# ...
        add g.make_button("g_12", "images/gallery/12.png", style="gallery_button") ## I think the style name is quoted, remove " if it errors

## OR

        add g.make_button("g_12", "images/gallery/12.png", xalign=0.5, yalign=0.5, hover_sound="audio/hoversound.mp3", activate_sound="audio/choicesound.mp3")
Frameworks & Scriptlets:

User avatar
chesarty
Regular
Posts: 116
Joined: Sat Aug 25, 2018 3:07 am
Completed: 0
Contact:

Re: Sounds for image gallery buttons

#3 Post by chesarty »

Remix wrote: Sat Oct 17, 2020 6:26 pm make_button() allows a style=style_name property and passes through **kwargs to Button so you could either pass a named style and add the hover_sound and activate_sound to that (likely best as you could also put your aligns there) or pass them as keyword arguments...

Code: Select all

style gallery_button is empty:
    align (0.5, 0.5)
    hover_sound "audio/hoversound.mp3"
    activate_sound "audio/choicesound.mp3"
    ## might need more style setting or inherit from something else

# ...
        add g.make_button("g_12", "images/gallery/12.png", style="gallery_button") ## I think the style name is quoted, remove " if it errors

## OR

        add g.make_button("g_12", "images/gallery/12.png", xalign=0.5, yalign=0.5, hover_sound="audio/hoversound.mp3", activate_sound="audio/choicesound.mp3")
Thank you! I used the 2nd option and it worked perfectly.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], haitai