Item/Coin Collection Sound Pitch Climb

tagwolf

Member
GM Version: 2.X
Target Platform: ALL
Download: N/A
Links: N/A

Summary:
A simple tutorial on making the climbing coin collection style sounds using a single wav file and GameMaker's audio_sound_pitch function. This tutorial gradually raises the sound if collection of the next item occurs within a set period of time and resets the sound back to default pitch once timed out.

Tutorial:

1) In a new or existing GMS2 project, create the following:

* A sprite named "spr_coin" (can be a simple circle for our purposes)
* A sound named "snd_piano" for purposes of this tutorial, use any short simple sound you want
* An object named "obj_controller_sound"
* An object named "obj_coin"
* A script named "scr_coin_collect_sound"


2) In "obj_coin" perform the following:

* Set the sprite to "spr_coin"
* Create a "Left Pressed" event with the following code:
Code:
scr_coin_collect_sound();
instance_destroy();

3) In "scr_coin_collect_sound" add the following code:
Code:
function scr_coin_collect_sound(){
	audio_play_sound(snd_piano,0,0);
	obj_controller_sound.alarm[0] = 120;
	if obj_controller_sound.pitch < 2 {
		obj_controller_sound.pitch += 0.1;
	}
	audio_sound_pitch(snd_piano,obj_controller_sound.pitch);
	//show_debug_message(string(obj_controller_sound.pitch))
}

4) In "obj_controller_sound" do the following:

* Create a "Create Event" with the following code:
Code:
pitch = 0.9;
* Create "Alarm 0" with the following code:
Code:
pitch = 0.9;

5) Place the following in your "Room"
* Multiple "obj_coin" instances. 30+
* The "obj_controller_sound" object in the upper left corner so it's out of the way.


6) Run your game and click on your coin objects! If you click them fast enough you should get a steady climbing sound up until you reach the max.

Feel free to tweak the numbers in the script and controller object to get different results!

Hope this helps! I know it was a quickie one so!

* NOTES: You will have to work out the interval if you want a particular scale of sound. the other option is to get samples of each sound you want and then create multiple sounds for each "note". Though this code would have to be tweaked a bit to support that it should give you an idea of how to implement it.
 
Top