Game Development Community

Playing Music

by Do Not Delete · in Torque X 2D · 08/29/2007 (3:10 pm) · 10 replies

I need help playing music using the Platformer Starter Kit's sound manager.

Here is the code:

public static void PlayMusic()
        {
            SoundManager.Instance.RegisterSoundGroup(@"data\sound\Win\Sound Bank.xsb", @"data\sound\Win\Wave Bank.xwb");

            Cue _music = SoundManager.Instance.PlaySound(@"data\sound\Win", "game_music");
        }
        public static void NewGame()
        {
            PlatformerStarter.Game.Instance.SceneLoader.Load(@"data\levels\sample_level.txscene");
            GUIStyle playStyle = new GUIStyle();
            GUISceneview play = new GUISceneview();
            play.Name = "PlayScreen";
            play.Style = playStyle;

            GUICanvas.Instance.SetContentControl(play);
            PlatformerDemoGUI.Instance.GUI.Folder = GUICanvas.Instance;

            PlayMusic();
        }

The sound code is currently in Level.cs a level manager class that I started writing. If this isn't the place please let me know!

The music doesn't play at all and I got it to work once, but forgot how.

Thanks,
YellowShadow

#1
08/29/2007 (4:24 pm)
Did you check the output window in Visual Studio for error messages? The sound manager is pretty good about reporting errors.
#2
08/29/2007 (4:57 pm)
I checked everywhere in the bottom but there is nothing. The game runs cleanly.
#3
08/29/2007 (8:29 pm)
Make sure your output window is set to Debug not Build.

Try taking out the \Win\ from the path and/or make sure the sound and wave bank files are actually in that directory in your bin folder.

If that doesn't work, set a break point and step through the PlaySound call with F11. Make sure the sound bank and wave bank are created correctly on the sound group and that the cue is created correctly.
#4
08/30/2007 (9:35 am)
I looked in the bin/debug folder and found out there are two of platformerdemo.xgs, Wave Bank.xwb and Sound Bank.xsb. The reason for this is because I would build the sound files in Xact and the Visual C# would build it during compile, so I took out the Win and Xbox folders and changed the code, but still nothing. Here is how the code currently looks like

public static void PlayMusic()
        {
            SoundManager.Instance.RegisterSoundGroup(@"data\sound\Sound Bank.xsb", @"data\sound\Wave Bank.xwb");

            Cue _music = SoundManager.Instance.PlaySound(@"data\sound\sound", "game_music");
        }

I'm going to debug in a little while and I'll post my results here.
#5
08/30/2007 (9:58 am)
I stepped through the code and I get this exception on both lines of code in public static void PlayMusic();

You must pass in a valid audio engine.
Parameter name: audioEngine

What does this mean?
#6
08/30/2007 (1:34 pm)
It means you have to enable audio in your project.

Add this...

<EnableAudio>true</EnableAudio>

...to the TorqueEngineSettings section of your torqueSettings.xml file (should be in the root of your project - same folder as Game.cs).

You also need to specify the settings file that's exported by the content pipeline. The beginning of your settings file should end up looking something like this:

<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<TorqueEngineSettings>
	<UseFixedTimeStep>true</UseFixedTimeStep>
	<EnableAudio>true</EnableAudio>
	<AudioGlobalSettingsFile>data\sound\GameFestDemo.xgs</AudioGlobalSettingsFile>
[...]

Also, in the version of the sound manager that ships with the kit, you have to use the same path you used to register the sound bank to use the sound group it's associated with. For example, in your case you would need to call:

SoundManager.Instance.PlaySound(@"data\sound\Sound Bank.xsb", "game_music");
#7
08/30/2007 (2:23 pm)
Thank you very much.
#8
08/30/2007 (4:59 pm)
I have some other questions. I added some code to play music when the game gets to the menu screen but it starts playing when the Splash Screen starts.

How would I do it so it starts playing when the game gets to the menu?

Also there are two menus, one is the main menu, and one is the single player menu. I want the menu music to stop when the I choose New Game. How would I do that?

Thanks,
Dro Sarhadian
#9
08/31/2007 (2:28 pm)
To get the sound to start with the menu, just wait to call PlaySound until you show the menu. You can stop a sound by storing a reference to the cue when you call PlaySound and then calling Stop on the cue when you want it to stop.
#10
08/31/2007 (4:44 pm)
How would I set a reference to the sound?