[Solved] How to play music at splashscreen, but not have it loop infinitely?

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
henvu50
Veteran
Posts: 337
Joined: Wed Aug 22, 2018 1:22 am
Contact:

[Solved] How to play music at splashscreen, but not have it loop infinitely?

#1 Post by henvu50 »

EDIT: The easiest solution is to comment out define config.main_menu_music = someMusic, like Alex said, but then just move everything from your splashscreen to before_main_menu. Then, in before_main_menu, play your music file with noloop added or loop=False. Using before_main_menu solved the issue, but if you want music to play alongside splashscreen, you move your splashscreen stuff to before_main_menu. Alex's last post is also important if you want to retain main music after the game has already started.!
_______

I want to play an intro song that starts at the splashscreen, but doesn't loop.

This is my code, but no matter what I try, the music keeps looping.

Code: Select all

define someMusic = 'song.ogg'
#script.rpy
init python:
     renpy.music.register_channel(name='music', mixer='music', loop=False, stop_on_mute=True, tight=False, file_prefix=u'', file_suffix=u'', buffer_queue=True, movie=False, framedrop=True)

label splashscreen:
    $ renpy.music.play(filenames=someMusic, channel='music', loop=False, if_changed=True,  fadein=4.0, fadeout=2.0)

#options.rpy
define config.main_menu_music = someMusic
Last edited by henvu50 on Mon Sep 06, 2021 10:33 pm, edited 5 times in total.

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

Re: How to play music at splashscreen, but not have it loop infinitely?

#2 Post by Alex »

Get rid of

Code: Select all

define config.main_menu_music = someMusic
and play main menu music like

Code: Select all

screen main_menu():
    on 'show' action Play('music', someMusic, loop=False, if_changed=True)

henvu50
Veteran
Posts: 337
Joined: Wed Aug 22, 2018 1:22 am
Contact:

Re: How to play music at splashscreen, but not have it loop infinitely?

#3 Post by henvu50 »

I'd prefer the music start at the splash screen. Oh well, this is not a big deal, but I was hoping I could gain absolute control of the audio.

Edit: Okay, this works for now. Stick this in the screen main_menu

Code: Select all

screen main_menu:
    # ......
    # disable music after a duration
    on 'show' action Show('timer_stop_audio')

screen timer_stop_audio(): 
    # as soon as this screen is shown, music stops after 60 seconds
    timer 60 action Stop('music', fadeout=2.0)

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

Re: How to play music at splashscreen, but not have it loop infinitely?

#4 Post by Alex »

henvu50 wrote: Mon Sep 06, 2021 9:30 pm I'd prefer the music start at the splash screen. ...

Code: Select all

label splashscreen:
    $ renpy.music.play(filenames=someMusic, channel='music', loop=False, if_changed=True,  fadein=4.0, fadeout=2.0) 
    return
Yes, you can start music at splashscreen (that's why if_changed=True is used in main menu).

Code: Select all

on 'show' action Play('music', someMusic, loop=False, if_changed=True)
This line will play music once again when you'll return to main menu from the game.

I didn't search the source code, but it seems like config.main_menu_music is looping.

henvu50
Veteran
Posts: 337
Joined: Wed Aug 22, 2018 1:22 am
Contact:

Re: How to play music at splashscreen, but not have it loop infinitely?

#5 Post by henvu50 »

Alex wrote: Mon Sep 06, 2021 10:13 pm
henvu50 wrote: Mon Sep 06, 2021 9:30 pm I'd prefer the music start at the splash screen. ...

Code: Select all

label splashscreen:
    $ renpy.music.play(filenames=someMusic, channel='music', loop=False, if_changed=True,  fadein=4.0, fadeout=2.0) 
    return
Yes, you can start music at splashscreen (that's why if_changed=True is used in main menu).

Code: Select all

on 'show' action Play('music', someMusic, loop=False, if_changed=True)
This line will play music once again when you'll return to main menu from the game.

I didn't search the source code, but it seems like config.main_menu_music is looping.
Thanks!

Post Reply

Who is online

Users browsing this forum: jeffster, risukadekei, Semrush [Bot]