Code: Select all
init python:
# run the melody on the channel
def mplay (fn, chan = "music", fin = 1.0, fout = 1.0):
renpy.play (fn + ".mp3", channel = chan, loop = True, fadein = fin, fadeout = fout)
# channel pause
def mpause (channel = "music"):
c = renpy.audio.audio.get_channel (channel)
c.pause ()
# remove from pause
def munpause (channel = "music"):
c = renpy.audio.audio.get_channel (channel)
c.unpause ()
# stop the melody
def mstop (chan = "music", fout = 1.0):
renpy.music.stop (channel = chan, fadeout = fout)
# test
label start:
$ mplay ("mus")
pause (2.0)
$ mpause ()
pause (2.0)
$ munpause ()
pause (2.0)
$ mstop ()
pause (2.0)
return
KeyAction = renpy.curry(function_name)
2) The music on the menu depends on the time of day
Download http://renpyfordummies.blogspot.com/201 ... t.html?m=1
Code: Select all
init python:
# game window - in the center of the screen
import os
os.environ ['SDL_VIDEO_CENTERED'] = '1'
# the function translates the current time into the name of the time of day
import datetime
def get_t ():
h = int (datetime.datetime.now (). strftime ("% H"))
res = "night" # default night
# borders of any time of day can be changed
if (h> 6) and (h <11):
res = "morning"
if (h> = 11) and (h <= 18):
res = "day"
if (h> 18) and (h <23):
res = "evening"
return res
last_t = None
# function changes music and lighting in the menu
# depending on the time of day
def change_mus ():
global last_t
if last_t! = get_t ():
last_t = get_t ()
# restart menu drawing
renpy.restart_interaction ()
# changing the melody in the main menu
config.main_menu_music = last_t + ".ogg"
if renpy.music.get_playing ()! = last_t + ".ogg":
renpy.music.play (last_t + ".ogg")
# function - in action
ChangeMus = renpy.curry (change_mus)
# picture for the main menu background
style.mm_root.background = "mm.jpg"
# in main_menu after style "mm_root":
# timer .05 repeat True action ChangeMus ()
# if last_t:
# add last_t
init:
# filters for lighting
image morning = "# 8404"
image day = "# 0000"
image evening = "# 0484"
image night = "# 000b"
# The game starts here.
label start:
"You have created a new Ren'Py game."
return
3) Play 2 sounds on channel 1 (for example, forest and melody, channel music)
Image code:
https://pp.userapi.com/c850016/v850016 ... CKrB8.jpg
Mixer="sfx" - channel sound
Mixer="music" - channel music
Code: Select all
init python:
renpy.music.register_channel("music_two", mixer="music", loop=True, stop_on_mute=True, tight=True, buffer_queue=True)
label start:
play music "mm.mp3"
play music_two "forest.mp3"
"text to the sound of 2 melodies"
Download https://yadi.sk/d/govNVgHZiEDA2
5)Until the music ends don't skip the scene
Url- https://pastebin.com/LCLqsyFA
Code: Select all
init python:
class __MusicInteract (renpy.Displayable):
__author__ = "Vladya"
def __init __ (self, filenames, channel = "music", * music_ar, ** music_kw):
super (__ MusicInteract, self) .__ init __ ()
self.channel = channel
self.music_data = {
"args": [filenames, channel] + list (music_ar),
"kwargs": music_kw
}
self .__ start_interact = False
def start_play (self):
renpy.music.play (
* self.music_data ["args"],
** self.music_data ["kwargs"]
)
self .__ start_interact = True
return ui.interact ()
def render (self, width, height, st, at):
if self .__ start_interact:
if not renpy.music.is_playing (self.channel):
renpy.end_interaction (st)
renpy.redraw (self, 0)
return renpy.Render (1, 1)
def play_interact (* args, ** kwargs):
u "" "
Pass arguments as usual 'renpy.music.play'.
Control will be returned to the player as soon as the audio file ends.
"" "
_music_object = __MusicInteract (* args, ** kwargs)
renpy.show ("musicInteractObject", what = _music_object)
play_time = _music_object.start_play ()
renpy.hide ("musicInteractObject")
return play_time
label start:
$ play_interact ("sound / file123.ogg", loop = False)
"The end of the song."
return
In the screen.rpy file, find the skip screen and add the following:
Code: Select all
screen skip_indicator ():
on 'show' action Play ('music', 'faster.mp3')
on 'hide' action Play ('music', 'normal.mp3')
Make a button (textbutton, imagebutton ...) and prescribe the action VoiceReplay () to it.
Usually it is better to shove it either in the quick menu or in the dialog box, and so that it does not interfere, we need to set a condition. As a result, we get
Code: Select all
if voice_can_replay():
imagebutton:
idle "images / gui / other / log_voice.webp"
hover "images / gui / other / log_voice.webp"
xalign 0.91 yalign 0.99
action VoiceReplay()
Code: Select all
screen galereya():
python:
renpy.music.play("menu.mp3", fadeout=10.0, fadein=15.0)
frame:
....
Code: Select all
define eva = Character(_("Girl"), voice_tag="female")
define dshon = Character(_("Boy"), voice_tag="boy")
screen preferences:
....
vbox:
textbutton _(" Disable voices for female characters") action ToggleVoiceMute("female")
textbutton _("Disable voices for boy characters") action ToggleVoiceMute("boy")
label start:
voice "f01.ogg"
eva "bla bla"
voice "b01.ogg"
dshon "bla bla"
Code: Select all
label start:
play music "horror.mp3"
$ renpy.music.set_volume (0.2)
"I'm getting closer to the room."
$ renpy.music.set_volume (0.5)
"I practically open the door."
$ renpy.music.set_volume (1.0)
"I'm in the room."