Book Image

Corona SDK Mobile Game Development: Beginner's Guide

By : Michelle M Fernandez
Book Image

Corona SDK Mobile Game Development: Beginner's Guide

By: Michelle M Fernandez

Overview of this book

Table of Contents (19 chapters)
Corona SDK Mobile Game Development Beginner's Guide Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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...