Article Tutorials/Intro to sounds
Now that we can display images and text on the screen, you’ll be wanting to make noise!
First, we’ll start with just sound effects.
Download all audio for this tutorial from: Gideros Mobile Tutorial Audio file (2.4Mb)
The easiest and cheapest way to get cool sound effects for your application is to use the funky BFXR which you can download from here:
This is a free-to-use and download application which lets you create sound effects and export the wav files of your effects for using in your application.
If you download the standalone version, you will need to install Adobe Air, but it’s worth it.
Click on the buttons until you find an effect you like and use Export Wav to save it into your Gideros Studio Project folder.
Create a new Project and add a new main.lua file to it. Use Add Existing Files to add your wav sound (eg laser.wav).
Type this into the main.lua file:
local laserfx = Sound.new("laser.wav") laserfx:play()
This creates an object called “laserfx” and loads the laser.wav file into it. The next line plays your sound effect. Pretty simple, huh?
Every game needs a funky tune in the background, so lets add in a tune. There’s plenty of free mp3s on the internet, so go grab your own and add it to the Project.
I grabbed a free tune from No Soap Radio (www.nosoapradio.us). They have a lot of game tunes, all totally free – even for commercial use!
local gametune = Sound.new("DST-AngryMod.mp3") gametune:play()
Now, if you launch your application you will hear the sound playing. Awesome!
The ‘play’ parameter has two options:
You can start your tune partway through the song by specifying the StartPosition option.
You can tell the tune how many times to loop (play over again) by specifying the Loops option.
local gametune = Sound.new("DST-AngryMod.mp3") gametune:play(100)
If you want to play the song repeating forever, use this:
Set the volume of your tune or sound effect:
“0.5” is at half volume. You can set your volume anywhere from 0 to 1.
Stop your tune from playing:
To unload and free up memory when you’re finished with your tune, use:
gametune = nil
Note: This tutorial was written by Jason Oakley and was originally available here: http://bluebilby.com/2013/04/18/gideros-mobile-tutorial-playing-music-and-sound-effects/.