Game Development Reference
In-Depth Information
would like the slider bar centered at the mouse x position, so we calculate the new
x position of the front sprite as follows:
back.GlobalPosition.X front.Width / 2
inputHelper.MousePosition.X
However, we also want to make sure that the slider bar stays within the boundaries
of the back sprite. Therefore, we use the MathHelper.Clamp method to clamp the value
between the minimal x value (which is back.Position.X + leftmargin ) and the maximal x
value (which is back.Position.X + back.Width front.Width rightmargin ). Finally, since
we are currently dragging, we set the value of the dragging member variable to true .
As soon as the left mouse button is released, we arrive at the alternative part of the if -
instruction, which sets the value of the dragging variable to false . This completes the
Slider class. For the complete code, see the PenguinPairs2 example project belonging
to this chapter.
Inside the PenguinPairs class, we then add a slider to the game world:
musicVolumeSlider = new Slider("Sprites/spr_slider_bar", "Sprites/spr_slider_button", 1);
musicVolumeSlider.Position = new Vector2(650, 500);
gameWorld.Add(musicVolumeSlider);
We can then use the Value property in that class to set the slider bar to match the
current volume of the background music with a single line of code:
musicVolumeSlider.Value = MediaPlayer.Volume;
Finally, in the Update method of the PenguinPairs class, we retrieve the current value
of the slider, and use that to update the volume of the background music:
MediaPlayer.Volume = musicVolumeSlider.Value;
Beautiful menu screens— Most games contain some menu screens. With
these screens, the player can set options, choose a level, watch achievements
or pause a game. Creating all of these additional screens can be a lot of work
that does not really contribute to the actual game play. So developers tend to
put less work into them. But that is a very wrong decision.
An artist once said: “Your game is as good as its worst screen”. If one of
the menu screens has poor quality the player will get the feeling that the game
is unfinished and that the developer did not put enough effort into it. So make
sure that all your menu screens look beautiful and are very easy to use and
navigate. Think carefully about what you put in these screens. You might be
tempted to create an option out of everything: the difficulty of the game, the
music to play, the color of the background, etc. But remember that you are the
person that should create the game, not the player. You or your artist should
determine what gives the most interesting gameplay and what gives the most
compelling visual style, not the user.
Search WWH ::




Custom Search