Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
L÷VE for Lua Game Programming

You're reading from   L÷VE for Lua Game Programming If you want to create 2D games for Windows, Linux, and OS X, this guide to the L?ñVE framework is a must. Written for hobbyists and professionals, it will help you leverage Lua for fast and easy game development.

Arrow left icon
Product type Paperback
Published in Sep 2013
Publisher Packt
ISBN-13 9781782161608
Length 106 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
AKINLAJA DAMILARE JOSHUA AKINLAJA DAMILARE JOSHUA
Author Profile Icon AKINLAJA DAMILARE JOSHUA
AKINLAJA DAMILARE JOSHUA
Arrow right icon
View More author details
Toc

Audio system


LÖVE leverages OpenAL for audio playback; it provides the love.audio module that uses only one type of object, a source file. It's simple to use, and wherever the callback love.audio.play() is put in a function, it plays the sound.

---fetch the audio file from source

BgSound = love.audio.newSource("bgsound.mp3", "stream")
--set the volume of the sound
BgSound:setVolume(0.5)
--set the pitch level
BgSound:setPitch(0.25)
--play the sound, you can also use shorthand BgSound:play()
love.audio.play(BgSound)

What we have done so far is to fetch the audio file to be played from source, set the volume and pitch, and then play it. In this case, the sound will stream from the disk compressed, unless it's specified as static. Static is good for short sound in which the sound is loaded into the memory; but for our background music, the sound will probably be long. So, we'll not use static but use stream, which means the sound will stream from disk without loading into memory first.

Enemy...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime