Reader small image

You're reading from  Corona SDK Mobile Game Development: Beginner's Guide

Product typeBook
Published inMar 2015
Publisher
ISBN-139781783559343
Edition1st Edition
Tools
Right arrow
Author (1)
Michelle M Fernandez
Michelle M Fernandez
Right arrow

Time for action – playing audio


We're going to learn how sound effects and music are implemented in Corona to get an idea of how it really works. To play an audio follow the steps:

  1. Create a new project folder on your desktop called Playing Audio.

  2. In the Chapter 6 Resources folder, copy the ring.wav and song1.mp3 sound files into your project folder and create a new main.lua file. You can download the project files that accompany this book from the Packt Publishing website.

  3. Preload the following audio with loadSound() and loadStream():

    ringSound = audio.loadSound( "ring.wav" )
    backgroundSound = audio.loadStream( "song1.mp3" )
  4. Play backgroundSound by setting it to channel 1, loop it infinitely, and fade in after 3 seconds:

    mySong = audio.play( backgroundSound, { channel=1, loops=-1, fadein=3000 }  )
  5. Add in ringSound and play it once:

    myRingSound = audio.play( ringSound )
  6. Save and run the project in the Corona Simulator to hear the results.

What just happened?

For audio that is merely a short sound...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Corona SDK Mobile Game Development: Beginner's Guide
Published in: Mar 2015Publisher: ISBN-13: 9781783559343

Author (1)