Gideros Mobile tutorial – Playing Music And Sound Effects

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 […]

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:

http://www.bfxr.net/

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.

bfxr

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

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:

• StartPosition
• Loops

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.

Eg.

local gametune = Sound.new("DST-AngryMod.mp3")
gametune:play(100,5)

If you want to play the song repeating forever, use this:

gametune:play(0, true)

Set the volume of your tune or sound effect:

sndChannel:setVolume(0.5)

“0.5” is at half volume. You can set your volume anywhere from 0 to 1.

Stop your tune from playing:

Soundchannel=gametune:play(0,true)
Soundchannel:stop()

To unload and free up memory when you’re finished with your tune, use:

gametune = nil

 

For more detailed information:

Tags:
Jason Oakley

About Jason Oakley