Lemma Soft Forums

Supporting creators of visual novels and story-based games since 2003.


Visit our new games list, blog aggregator, IRC, and wiki.
Activation problem? Email [email protected]
It is currently Tue May 21, 2013 10:46 pm

All times are UTC - 5 hours [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: Mon Jan 02, 2012 7:55 pm 
Newbie

Joined: Mon Jan 02, 2012 4:50 pm
Posts: 2
I'd like to have the option of playing my game's music from the main menu, but the tutorials and guides provided only confuse me more. I'd really appreciate some help.


Top
 Profile Send private message  
 
PostPosted: Tue Jan 03, 2012 1:16 pm 
Lemma-Class Veteran

Joined: Tue Aug 01, 2006 12:39 pm
Posts: 4051
You know what, let's edit and customize the main menu portion in screens.rpy so it can use nice buttons (which I place in /game/gui/):
Code:
screen main_menu:

    # This ensures that any other menu screen is replaced.
    tag menu

    # The background of the main menu.
    window:
        style "mm_root"

    # The main menu buttons.
    frame:
        background None
        style_group "mm"
        xoffset 25
        yoffset 150

        has vbox

        imagebutton:
            action Start()
            idle "gui/New1.png"
            hover "gui/New2.png"
        imagebutton:
            action ShowMenu("load")
            idle "gui/Continue1.png"
            hover "gui/Continue2.png"
        imagebutton:
            action ShowMenu("preferences")
            idle "gui/Options1.png"
            hover "gui/Options2.png"
        imagebutton:
            action ShowMenu("music_room")
            idle "gui/Music1.png"
            hover "gui/Music2.png"
        imagebutton:
            action Quit(confirm=False)
            idle "gui/Quit1.png"
            hover "gui/Quit2.png"


Hmmm, so now there's a button leading to the music room! (It's a similar process if you want to add a button to your Gallery)

But I need to
1.) Tell the system I have music tracks
2.) Set up a basic player layout to play them

Put this anywhere (but usually at the bottom of options.rpy or screens.rpy, your choice). Let's assume for a moment you only have 4 tracks, all of them in /game/music subfolder.
Code:
#Hey Renpy I got some music tracks...
init python:
    # Step 1. Create a MusicRoom instance.
    mr = MusicRoom(fadeout=1.0)
    # Step 2. Add music files.
    mr.add("music/introvoiceless.ogg", always_unlocked=True)
    mr.add("music/intro.ogg", always_unlocked=True)   
    mr.add("music/insecure.ogg", always_unlocked=True)     
    mr.add("music/explore.ogg", always_unlocked=True)

#Hey Renpy now I gotta make a player to play em...
screen music_room:

    tag menu
    window:
        background "gui/musicroombg.jpg"

    imagebutton: #I need a way to get back to the main menu
        action Return()
        idle "gui/Return1.png"
        hover "gui/Return2.png"
        xanchor 0 yanchor 0
        xpos 5 ypos 15               
       
    frame: #these positioning changes depending on your layout
        xpos 350
        ypos 10
        has vbox:
            xalign 0.5
            yalign 0.5

        # The buttons that play each track.  MUST CORRESPOND TO THE TRACK LIST ABOVE
        textbutton "Voiceless Intro" action mr.Play("music/introvoiceless.ogg")
        textbutton "Voiced Intro" action mr.Play("music/intro.ogg")
        textbutton "Insecure Theme" action mr.Play("music/insecure.ogg")
        textbutton "Exploration Theme" action mr.Play("music/explore.ogg")
       
    frame:
        xpos 350
        ypos 410
        has hbox:
            xalign 0.5
            yalign 0.5
       
        # Buttons that let us advance tracks.
        textbutton "|<<" action mr.Previous()       
        textbutton ">>|" action mr.Next()

    # Start the music playing on entry to the music room.
    on "replace" action mr.Play()

    # Restore the main menu music upon leaving.
    on "replaced" action Play("music", "music/maintitletheme.ogg")


Top
 Profile Send private message  
 
PostPosted: Tue Jan 03, 2012 1:20 pm 
Eileen-Class Veteran
User avatar

Joined: Sat Apr 23, 2011 2:43 pm
Posts: 1086
Completed: Ristorante Amore, The Elevator, SPLENDIDEST OTOGE
Projects: Break Chance Memento, Swan Grimoire
Organization: Cyanide Tea
Ok sorry if anyone saw my post before I deleted it. I remembered that there's a screen-based Music Room that was more or less added in a recent Ren'Py release, so I read through that first and this one's much easier to implement than the cookbook version. Follow along with this page from the documentation.

Here are the steps according to the documentation. The elaboration is my own.

1. Create an instance of MusicRoom. The MusicRoom constructor takes parameters to control the channel on which music is played back, and how long it takes to fade music out and back in.
Following the documentation, you just have to put in this code somewhere:
Code:
init python:

    # Step 1. Create a MusicRoom instance.
    mr = MusicRoom(fadeout=1.0)

As long as it's in a .rpy file, it should be fine. Feel free to add it to an existing .rpy file or make a new one if it'll help with organization. Make sure you watch your indentation. The fadeout=1.0 part is the parameter that tells "how long it takes to fade music out and back in". So the higher the number, the longer the fade/transition.

2. Add music files to the instance.
Note that these should still be in the init python block and underneath previous code. So all told, it should look like this:
Code:
init python:

    # Step 1. Create a MusicRoom instance.
    mr = MusicRoom(fadeout=1.0)

    # Step 2. Add music files.
    mr.add("track1.ogg", always_unlocked=True)
    mr.add("track2.ogg")
    mr.add("track3.ogg")

Add all the tracks of your game here in that format. Again, watch indentation. If you want the track to always be unlocked, add that always_unlocked=True parameter. If it's not there, then the track will only show up if the player has already heard it in the game in at least one playthrough.

3. Create a screen that uses the MusicRoom instance to create actions for buttons, imagebuttons, or hotspots. These actions can pick a track, the next or previous track, or stop and start the music.
This is uh basically where you create the actual music room screen. The documentation gives a good sample code that you can use:
Code:
screen music_room:

    tag menu

    frame:
        has vbox

        # The buttons that play each track.
        textbutton "Track 1" action mr.Play("track1.ogg")
        textbutton "Track 2" action mr.Play("track2.ogg")
        textbutton "Track 3" action mr.Play("track3.ogg")

        null height 20

        # Buttons that let us advance tracks.
        textbutton "Next" action mr.Next()
        textbutton "Previous" action mr.Previous()

        null height 20

        # The button that lets the user exit the music room.
        textbutton "Main Menu" action ShowMenu("main_menu")

    # Start the music playing on entry to the music room.
    on "replace" action mr.Play()

    # Restore the main menu music upon leaving.
    on "replaced" action Play("music", "track1.ogg")

Personally I would place this in the screens.rpy file with all the other screen definitions, but again you can put this anywhere. And again, you should be careful with your indentation. The # notes explain pretty much what every bit of used code in this screen does. Please note that pausing is not currently supported in Ren'Py so you can only stop, play, and skip forwards or backwards a track. "Note that the actions used are members of a MusicRoom instance, so if the MusicRoom instance is named mr, then mr.Play("track1.ogg") is how you'd use the play action." If you use this exact code, you don't have to worry about this part, but if you change that very first definition, ie:

Code:
musiroo = MusicRoom(fadeout=1.0)

Then all the resulting code would be musiroo.X instead of mr.X, if that makes sense.

4. Add the music room screen to the main menu, or an extras menu.
Well DaFool beat me to the punch while I was typing this up and pretty much nicely explained this step, so just listen to him. xD Basically you just add a button to your main_menu screen in the screens.rpy file.

_________________
1/2 of Cyanide Tea | BCM | Ristorante Amore | The Elevator | @Twitter


Top
 Profile Send private message  
 
PostPosted: Tue Jan 10, 2012 7:25 pm 
Newbie

Joined: Mon Jan 02, 2012 4:50 pm
Posts: 2
Well, do I need to actually make the images for all this??
I try and script this all out but the button still doesn't show up.


Top
 Profile Send private message  
 
PostPosted: Thu Jan 12, 2012 4:27 am 
Lemma-Class Veteran

Joined: Tue Aug 01, 2006 12:39 pm
Posts: 4051
Yes, you need to have all the files, images and music ready.


Top
 Profile Send private message  
 
PostPosted: Thu Jan 12, 2012 10:11 pm 
Regular
User avatar

Joined: Sat Oct 15, 2011 1:03 am
Posts: 71
Location: Colombia
Projects: Tell me about your school days
Camille wrote:
Ok sorry if anyone saw my post before I deleted it. I remembered that there's a screen-based Music Room that was more or less added in a recent Ren'Py release, so I read through that first and this one's much easier to implement than the cookbook version. Follow along with this page from the documentation.

Here are the steps according to the documentation. The elaboration is my own.

1. Create an instance of MusicRoom. The MusicRoom constructor takes parameters to control the channel on which music is played back, and how long it takes to fade music out and back in.
Following the documentation, you just have to put in this code somewhere:
Code:
init python:

    # Step 1. Create a MusicRoom instance.
    mr = MusicRoom(fadeout=1.0)

As long as it's in a .rpy file, it should be fine. Feel free to add it to an existing .rpy file or make a new one if it'll help with organization. Make sure you watch your indentation. The fadeout=1.0 part is the parameter that tells "how long it takes to fade music out and back in". So the higher the number, the longer the fade/transition.

2. Add music files to the instance.
Note that these should still be in the init python block and underneath previous code. So all told, it should look like this:
Code:
init python:

    # Step 1. Create a MusicRoom instance.
    mr = MusicRoom(fadeout=1.0)

    # Step 2. Add music files.
    mr.add("track1.ogg", always_unlocked=True)
    mr.add("track2.ogg")
    mr.add("track3.ogg")

Add all the tracks of your game here in that format. Again, watch indentation. If you want the track to always be unlocked, add that always_unlocked=True parameter. If it's not there, then the track will only show up if the player has already heard it in the game in at least one playthrough.

3. Create a screen that uses the MusicRoom instance to create actions for buttons, imagebuttons, or hotspots. These actions can pick a track, the next or previous track, or stop and start the music.
This is uh basically where you create the actual music room screen. The documentation gives a good sample code that you can use:
Code:
screen music_room:

    tag menu

    frame:
        has vbox

        # The buttons that play each track.
        textbutton "Track 1" action mr.Play("track1.ogg")
        textbutton "Track 2" action mr.Play("track2.ogg")
        textbutton "Track 3" action mr.Play("track3.ogg")

        null height 20

        # Buttons that let us advance tracks.
        textbutton "Next" action mr.Next()
        textbutton "Previous" action mr.Previous()

        null height 20

        # The button that lets the user exit the music room.
        textbutton "Main Menu" action ShowMenu("main_menu")

    # Start the music playing on entry to the music room.
    on "replace" action mr.Play()

    # Restore the main menu music upon leaving.
    on "replaced" action Play("music", "track1.ogg")

Personally I would place this in the screens.rpy file with all the other screen definitions, but again you can put this anywhere. And again, you should be careful with your indentation. The # notes explain pretty much what every bit of used code in this screen does. Please note that pausing is not currently supported in Ren'Py so you can only stop, play, and skip forwards or backwards a track. "Note that the actions used are members of a MusicRoom instance, so if the MusicRoom instance is named mr, then mr.Play("track1.ogg") is how you'd use the play action." If you use this exact code, you don't have to worry about this part, but if you change that very first definition, ie:

Code:
musiroo = MusicRoom(fadeout=1.0)

Then all the resulting code would be musiroo.X instead of mr.X, if that makes sense.

4. Add the music room screen to the main menu, or an extras menu.
Well DaFool beat me to the punch while I was typing this up and pretty much nicely explained this step, so just listen to him. xD Basically you just add a button to your main_menu screen in the screens.rpy file.


Well, if it´s not a bother, i´d like to ask you something. In the previous recipe, the one in the cookbook, you can see a "???" (or whatever you´d like to put in there) in the button when you haven´t unlocked the track yet. That was the only thing of that recipe i really liked, do you think there is a way i can do that in this recipe? You know the old recipe is written in that old language so i don´t really know how to "write it" in screen language. I´d really thank any help.

_________________
Image
[WIP]Tell me about your shool days[WIP]


Top
 Profile Send private message  
 
PostPosted: Tue Mar 13, 2012 8:37 am 
Eileen-Class Veteran
User avatar

Joined: Thu Oct 14, 2010 3:53 am
Posts: 1070
Location: NC, USA
Completed: Torrey & the Vampire, Faery Tale, Madaline's Missing Miscellany, Alchemical Ink, Yaoi Story, The Visitor, Erotic Story Generator, What Kind of Fiction Should YOU Write? (Quiz Game), Falling
Organization: Erotic Visions - VNs
Thank you so much for these excellent tutorials!

Between DaFool's and Camilla's crystal clear instructions on making a music room, plus tweeking with Camille's Crash Course in GUI design, and Aleema's menu customization tutorial, I was able to make a rather nice-looking music room that works beautifully from my Bonus page.

Thank you so much for sharing your expertise! Us lesser beings truly, truly appreciate it.


Attachments:
ScreenShot05.jpg
ScreenShot05.jpg [ 447.35 KiB | Viewed 1356 times ]
ScreenShot04.jpg
ScreenShot04.jpg [ 429.62 KiB | Viewed 1387 times ]

_________________
Ookami Kasumi ~ Purveyor of fine Smut.
Erotic Visions ~ Visual Novels

"No amount of great animation will save a bad story." -- John Lasseter of Pixar
Top
 Profile Send private message  
 
PostPosted: Mon Jul 30, 2012 2:29 pm 
Eileen-Class Veteran
User avatar

Joined: Thu Oct 14, 2010 3:53 am
Posts: 1070
Location: NC, USA
Completed: Torrey & the Vampire, Faery Tale, Madaline's Missing Miscellany, Alchemical Ink, Yaoi Story, The Visitor, Erotic Story Generator, What Kind of Fiction Should YOU Write? (Quiz Game), Falling
Organization: Erotic Visions - VNs
This really needs to go into the Renpy Cookbook part of the Forum.
-- It's accurate and very easy to use.

_________________
Ookami Kasumi ~ Purveyor of fine Smut.
Erotic Visions ~ Visual Novels

"No amount of great animation will save a bad story." -- John Lasseter of Pixar


Top
 Profile Send private message  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 5 hours [ DST ]


Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Protected by Anti-Spam ACP
Powered by phpBB® Forum Software © phpBB Group