Forum Thread
XNA: probs with sound, making menus, etc... :( (Forums : Coding & Scripting : XNA: probs with sound, making menus, etc... :() Locked
Thread Options
Aug 13 2012 Anchor

Hi everyone :).

Basically i have been following a tutorial on making a 2D XNA game. I have finished the tutorial and i am trying to add some features to the game myself.

One of the features i am trying to add or even control is the game volume. There are multiple sound effects already included in my game, such as the launching of the rocket from the cannon, rocket colliding with the terrain and also colliding with another player.

I have looked this up already and all i have found are solution that seem very ... well lets say more complex then they need to be it seems... (some solutions i found were on the MSDN website, which in my opinion arn't always the best or provide the easiest solutions...)

What i want to do then is to be able to mute and unmute the game sound.

Here is some code to try to explain and show what i have done or what is available atm:

//declaring variables for each sound effect

SoundEffect hitCannon;
SoundEffect hitTerrain;
SoundEffect launch;

//Loading the sound effects into the game

hitCannon = Content.Load<SoundEffect>("hitcannon");
hitTerrain = Content.Load<SoundEffect>("hitterrain");
launch = Content.Load<SoundEffect>("launch");

//code from method that processes user input

if (keybstate.IsKeyDown(Keys.Enter) || keybstate.IsKeyDown(Keys.Space))
                rocketFlying = true;

The code for the other 2 variables have also been written, so i havent not written them (so i have written them :)) but i havent included them in the code above, as they are both basically the same as the code for playing the launch sound, so hitCannon.Play();, etc.

I will try to keep this as brief as possible, (without making a new thread :S) but i am also (and i have always wanted to know how to do this in XNA) trying to create some form of menu. I think creating a main menu would be the best place to start lol, however i would also like to know how to create a pause menu and any other type of menu that may be relevant.

I would appreciate any info on creating menus, so pointing me in the right direction, in terms of how to go about making menus would be great, i mean obviously i dont expect anyone to just give me code and for me to copy and paste it, as that wouldnt be too helpful for me gaining knowledge and im sure you wouldnt want me using your code :)....

So yea, thats it from me, hopefully this isn't as demanding or anything as other posts/essays i have created :D LOL.

Thanks again everyone for the help and your time.

Aug 13 2012 Anchor

if you want to make like menus, like main menu to start game, credits screen, options screen, etc. I used this guys class. you can download it there.

you can also use an enum to change the gamescreen,
kinda like:

public enum gameScreen
in the constructor you would put like this
gameScreen currentscreen=gameScreen.start

in the update thread you would have an if statement for it then can change what the currentscreen value is to change the screen page

Here is some of my implementation for putting buttons, and detecting it via the mouse, then the button color changes when the mouse hovers over it

 globalvariables.globalpictured.Draw(globalvariables.newgamebutton, new Vector2(325f, 200.0f), Color.White);//draw normal button

  if ((mousex < 460 &amp;&amp; mousex > 310) &amp;&amp; (mousey > 188 &amp;&amp; mousey < 222))
                globalvariables.globalpictured.Draw(globalvariables.newgamebuttonover, new Vector2(325f, 200.0f), Color.White);

                if (ButtonState.Pressed == mouseState.LeftButton)
                    globalvariables.globalplayerlives = 30;
                    globalvariables.globallevelintegervalue = 1;

Edited by: atsebak

Aug 14 2012 Anchor

I actually wrote an entire form/GUI system myself from scratch. It works much better, since when you make it yourself it's much more flexible and "custom" to your game than just using someone else's libraries.

I work with an 'interface' principle;

Public Interface IForm

    Sub Draw(ByVal GraphicsDevice As GraphicsDevice, ByVal SpriteBatch As SpriteBatch)
    Sub Update(ByVal GameTime As GameTime)

End Interface

This interface is then implemented by classes, one class for every form/screen (main menu, options, game, etc) and a currently active form is then drawn through the main game class:

Public Class SolitudeGame
    Inherits Game

    Public WithEvents Graphics As GraphicsDeviceManager
    Private WithEvents SpriteBatch As SpriteBatch

    Public ActiveForm As IForm

    ' ........

    Protected Overrides Sub Initialize()
        ActiveForm = New FormMainMenu
    End Sub

    Protected Overrides Sub Update(ByVal gameTime As GameTime)
        If ActiveForm IsNot Nothing Then ActiveForm.Update(gameTime)
    End Sub

    Protected Overrides Sub Draw(ByVal gameTime As GameTime)

        If ActiveForm IsNot Nothing Then ActiveForm.Draw(GraphicsDevice, SpriteBatch)
    End Sub

End Class

(Obviously, I'm leaving out all the code that's not relevant)

The form can then be changed by setting the game class's ActiveForm property to something else.
This system has proved to be pretty damn reliable so far...


The Enrichment Center is required to remind you that MSBuild cannot speak. In the event that MSBuild does speak, the Enrichment Center urges you to disregard its advice.

Aug 14 2012 Anchor

Thanks for the post atsebak and NtWuff! :)

I will try to translate the VB code to C# code :). VB was actually my first language i was learning and i did try using VB with XNA, however i found that there wasnt that much support for it, although im sure there will be more support for it in the future, its just a matter of time :).

atsebak, i didnt really understand the globalvariables thing (soz :S). I mean, of what type is globalvarialbes? Would i have to create some objects?

Thanks :)


I wrote: "The solution to any problem is to break it up into smaller parts and attack it with logic"

I wrote: "I hate the term 'coding', as it's being thrown around alot by what seems to be the code monkeys, as oppose to the others that stand back and try to solve the problem logically first. FYI I prefer the term 'programming'.

This seems to be an interesting read: This also shows the a programmer requires more skill than is required for a coder, so a programmer would therefore be a more valuable asset to a team compared to a coder."

User Posted Image

Aug 14 2012 Anchor

globalvariables was the name of one of my classes it was basically all global variables in it to make a global variable u just write public static datatype

Edited by: atsebak

Aug 15 2012 Anchor

There still isn't much support for VB on XNA, but it works properly when you install the Windows Phone SDK as well, which adds the XNA project templates to the VB.NET categories.

When you get that form system working, you can start actually writing GUI components. So far I've got a text box, combobox, buttons, list boxes...
Happy to help!


The Enrichment Center is required to remind you that MSBuild cannot speak. In the event that MSBuild does speak, the Enrichment Center urges you to disregard its advice.

Reply to thread
click to sign in and post

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.