Music doesn't fadeout

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
lykoia
Newbie
Posts: 22
Joined: Tue Apr 14, 2020 11:15 am
Contact:

Music doesn't fadeout

#1 Post by lykoia »

Hello, newbie here.

I wanted to make the music fade out but it just simply doesn't work.
Here's the code:

Code: Select all

scene old-park-entrance with fade
stop music fadeout 3.0
play music "forest.mp3" loop fadein 3.0
I'm not sure what I did wrong but only the fade in from forest.mp3 works but the fadeout for all music.

Thank you in advance

User avatar
hell_oh_world
Miko-Class Veteran
Posts: 777
Joined: Fri Jul 12, 2019 5:21 am
Contact:

Re: Music doesn't fadeout

#2 Post by hell_oh_world »

lykoia wrote: Thu May 07, 2020 9:17 am Hello, newbie here.

I wanted to make the music fade out but it just simply doesn't work.
Here's the code:

Code: Select all

scene old-park-entrance with fade
stop music fadeout 3.0
play music "forest.mp3" loop fadein 3.0
I'm not sure what I did wrong but only the fade in from forest.mp3 works but the fadeout for all music.

Thank you in advance
I think you can also do

Code: Select all

play music "forest.mp3" loop fadein 3.0 fadeout 3.0
i haven't had much experience with music though...

User avatar
Milkymalk
Miko-Class Veteran
Posts: 753
Joined: Wed Nov 23, 2011 5:30 pm
Completed: Don't Look (AGS game)
Projects: KANPEKI! ★Perfect Play★
Organization: Crappy White Wings
Location: Germany
Contact:

Re: Music doesn't fadeout

#3 Post by Milkymalk »

That solution will first fade out the old music, then fade in the new one. For a cross-fade, you can use a second channel:

Code: Select all

default active_music_channel = 'music'	# stores which channel is playing and which not
default inactive_music_channel = 'music2'
 
init python:
    renpy.music.register_channel('music2')	# register the new channel for renpy
     
    def playmusic(name, fade=3.0):	# standard fade is 3 seconds
        global active_music_channel, inactive_music_channel	# be able to change the two "stores"
        active_music_channel, inactive_music_channel = inactive_music_channel, active_music_channel	# swap the two "stores"
        renpy.music.stop(channel=inactive_music_channel, fadeout=fade)	# fade out the music in one channel ...
        renpy.music.play(name, channel=active_music_channel, fadein=fade)	# and fade in the music in the other channel
         
label start:
	$ playmusic('forest.mp3')
	"wait for a few seconds, then click"
	$ playmusic('othermusic.mp3')
	"see?"
Crappy White Wings (currently quite inactive)
Working on: KANPEKI!
(On Hold: New Eden, Imperial Sea, Pure Light)

Post Reply

Who is online

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