Level: Beginner
Playing Sounds & Music
Every game plays back sound effects and background music. This section covers the basics of importing music, playing it back and some interesting tidbits that may not be so obvious at first.
Contents
-
Importing Sounds
-
Example: Background Music
-
Accepted Formats
-
Music vs. Sound Effects
-
Playing Sounds
-
Channels
-
MP3 Licensing
-
The Future
-
Challenge: Zelda-Style Battle Music
-
Challenge: Smooth Looping
How to: Importing Sounds & Music
1) Import music into the Sound Editor by going to File > Create New > Sound.
2) Give it a name.
3) Click the following box to pick and import.

Tip: Alternatively, you can just drag and drop the sound in. This is much quicker for some, and you don’t even need to have the Sound Editor opened to do this.)
Example: Background Music
Looping "background" music takes just 1 block to do.
Make a Scene Behavior out of this, or stick this directly into the "Events" for a scene.

Note: There's a flaw in this approach. Think about what happens when you re-enter this scene... That isn't desirable, is it?
Later in this article, we cover all the playback blocks available to you.
Accepted Formats
At this point in time, Stencyl only accepts MP3s. We plan to add additional formats in Stencyl 2.5.
Note: We recommend
Audacity for exporting MP3s. It’s free.
For Flash games, the MP3s are used directly. For mobile games, the MP3s are converted, using the iOS or Android SDK, to native formats for phones.
If possible, import MP3’s in the following format.
-
44.1 KHz (versus 22 or 11)
-
16-bit
-
Constant bitrate (versus VBR)
-
No metadata
If your game unexpectedly does not export your game to Flash, it’s likely that sounds are the culprit. Post your issue to the forums and generate logs. We’ll be happy to check it out. (TODO: Take this note out and tell users how to solve it on their own.)
Why doesn't Stencyl accept more formats?
The reason why Stencyl does not offer this capability out of the box is due to the MP3 encoding patent held by several large companies. We are unable to offer software that converts from [FORMAT YOU HAVE] to MP3.
Thankfully, this will change with the ability to playback these other formats natively in future versions of Stencyl.
Music vs. Sound Effects
You may have noticed the following dropdown inside the Sound Editor. What does it mean?

Music is streamed (like viewing a YouTube video) since it’s too large to fit into memory. This is best for background music.
Sound effects are loaded into memory to reduce latency in playback. This is better for short clips that need to be played immediately.
How to Play Sounds & Music
All sound-related blocks are conveniently located under the Sound category.

Play = Plays to the end once, then stops
Loop = Plays to the end and then repeats
Volume ranges between 0% and 100%, inclusive.
Note: If you’d like to pause and resume a sound, skip down to the “Channels” section.
Note: Looping music does not stop upon switching scenes. A common mistake, however, is to attach a “Background Music” behavior to every scene, causing the music to restart each time you enter a new “room.” How would you solve this?
Channels
Suppose that you’re playing Zelda. The regular tune plays, but when you approach an enemy, and the music switches over to the battle music. Once you defeat the enemy, the regular tune picks up where it left off.
Channels are a simple way to refer back to the playback of sounds, so that you can control their volume and pause/resume them in the future.

Channels are referred to by number, starting at index 0, ending at index 31.
32 channels are available in total.
Note: When you play a sound/music without specifying a channel, Stencyl picks the next available channel starting from 0. If none are available, nothing happens.
MP3 Licensing
On occasion, we get questions about MP3 Licensing.
For Flash games, licensing is already handled by Adobe (the creator of Flash), and as a game developer, you do not have to worry about licensing for your Flash game. The same goes for standalone games, which as of Stencyl 2.0, are also generated using Adobe's tools.
For mobile games, your sounds are converted, using Apple’s or Google’s standard developer tools into the devices’ native formats (such as AIFC, CAF) and never play as MP3’s on those devices.
The Future
We are planning to support more sound types in the future and would like to directly support OGG, WAV and possibly sequenced formats such as MIDI and tracker music (XM, IT).
On top of that, we’re also planning to add more control over playback, such as panning, altering pitch, seeking to a certain point in a clip and more.
Summary
-
Music = Streamed, Sound Effects = Loaded into Memory
-
Channels let you control playback. They have little to do with the regular meaning of sound channels.
-
Don’t worry about MP3s - Adobe has you covered. On mobile, your game never plays MP3’s.
Challenge: Zelda-style Battle Music
“Suppose that you’re playing Zelda. The regular tune plays, but when you approach an enemy, and the music switches over to the battle music. Once you defeat the enemy, the regular tune picks up where it left off.”
How would you build this sound system?
Challenge: Smooth Looping
MP3's can sometimes have a hard time looping smoothly and seamlessly. Some pieces of software are able to mask this or work it out. One of our users posted up an interesting link talking about a guaranteed-way of creating gapless MP3's.
http://www.compuphase.com/mp3/mp3loops.htm
He put up a shorter guide here.
Your task is simple - run through it and see if it works for you. It's a long article, and if you are able to boil that down to a smaller series of steps, we've love to know about it (in the comments section here!)
Last Updated: 2013-04-10 by Jon
13003 have read this article
Disclaimer: The Stencyl Team does not actively monitor comments on articles. If you're seeking help for your game,
please ask a question on the forums. Thanks!
Sign In to Comment