Tutorial
Page 14 of 15
Final Polish - Control
The final thing we are going to add to the game is a controller object. Many games have special objects with no sprites assigned to them that are used to control elements of the game that are not
directly related to the gameplay. In this case, our controller will show the score and play some background music.
First lets add some music to the resources for the game:
- From the Resources drop down menu, choose Create Sound, which will open a new Sound Properties window. Click on the Name field and rename it to "snd_music".
- Click on the Load Sound button, navigate to the Resources folder and select the sound file music.mp3.
- We don't need to change anything else here as GameMaker will detect that it is an *.mp3 file and make the necessary changes. Note that this sound file uses the *.mp3 format
as it keeps the file size smaller, and this follows the general rule of thumb that *.wav files are for sound effects and *.mp3 files are for music. Now press the "OK" button to close the
window.
Create a new object by opening the Resources drop down menu and selecting Create Object, or by right clicking on the "Objects" folder in the resource tree and selecting "New
Object. Give this object the name "obj_control" and add a Create Event to it. In this event, drag a Play Sound action into it and for a sound indicate "snd_music" and set
Loop to true because we want the music to repeat itself forever while playing.
We want to display the player score with this object too, so you need to add a Draw Event to your object. In this Draw Event you should go to the Score tab and drag the Draw
Score action into the action list.
The position for drawing the score is defined by the x and y values that you input here, so set them both to 64, and leave the "Caption" as it is, since it is the score we are showing and not some other value.
The last thing we need to do is to add this object into the room, so double click the game room to open it again a,d then in the Objects tab, select "obj_control" and place it in the room anywhere.
Since the object does not have a sprite, you will see that GameMaker shows you it's position with a little blue ball marker with a question mark. this will not be shown in the game and is only there as a
reminder to you that you have placed a spriteless instance in the room.
Run the game now and see how everything works together!
© Copyright YoYo Games Ltd. 2014 All Rights Reserved