Sound is a fundamental aspect of almost any game. This section covers the basics of importing music, playing it back and some interesting tidbits that may not be obvious.
Contents
- Importing Sounds
- Example: Background Music
- Accepted Formats
- Music vs. Sound Effects
- Playing Sounds and Music
- Channels
- Known Issues
- Challenge: Zelda-Style Battle Music
- Challenge: Smooth Looping
How to: Importing Sounds & Music
-
Import the clip into the Sound Editor by going to File > Create New > Sound.
-
Give it a name.
- Click the following box to pick and import.
Tip: Alternatively, you can just drag and drop the sound in.
Example: Looping 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.
Exercise: 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'll cover all the playback blocks available to you.
Accepted Formats
Stencyl accepts MP3s and OGGs as follows.
Platform | Accepted Format |
---|---|
Flash | MP3 |
HTML5 | OGG |
Windows | OGG |
Mac | OGG |
Linux | OGG |
iOS | OGG |
Android | OGG |
In short, we use OGG for every platform except for Flash. If you're publishing your game to Flash and any of the other platforms, you'll need to import the sound in both formats. (We recommend Audacity for exporting music. It’s free.)
MP3 Troubleshooting
If your game unexpectedly does not export your game to Flash, it’s likely that sounds are the culprit. Ensure that your MP3's meet the following specifications.
- 44.1 KHz (versus 22 or 11)
- 16-bit
- Constant bitrate (versus VBR)
- No metadata
If you continue to experience issues with MP3s, post your issue to the forums and generate logs.
MP3's and Licensing
For Flash games, licensing is handled by Adobe (the creator of Flash), and as a game developer, you do not have to worry about licensing for your Flash game, even if it makes money.
For desktop and mobile games, we only work with OGG sounds, so the use of MP3's is irrelevant.
Music vs. Sound Effects
Stencyl supports two kinds of sounds: music and sound effects.
Music is streamed (like viewing a YouTube video) since it’s too large to fit into memory. This is best for background music. This incurs a small performance penalty on mobile devices.
Sound Effects are loaded into memory to reduce latency in playback. This is better for short clips that need to be played immediately but consumes memory, particularly on mobile devices.
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.
A Common Mistake: Looping Music
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” or "stack up."
How would you solve this? One approach is to create a blank scene prior to the first level which loops the music. Since this scene is not encountered again, the loop behavior runs just once.
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 a playback instance 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.
Known Issues
On the Android target, playing sounds may be delayed by a quarter to half second on some devices. This is due to a bug in Android's sound APIs. As of late 2015, this bug still exists and afflicts all products that use this API.
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 other platforms, we now use OGGs.
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?
Print Article Edit Article How to Edit an Article18 Comments
I think it should be important to note that only 1 sound can play on 1 channel at a time.
I didn't know this at first and I thought I was doing something wrong and I tried to fix it for like 30 minutes until I figured it out.
I know, basic mistake, but you know how it goes...
0
I am having trouble with pausing my background music. I want to be able to pause the music and resume it from where it last left off, which, I think, involve the use of channels. How do I use them?
0
OneSaint, why don't you just create a single audio file with many different instances of the original cheer sound effect played over a couple audio beds? That way it only plays one sound, but it can still repeat the sound effect and overlap as many times as needed.
0
I'm also stuck on sound bugs too.. ahhh... it makes me crazy LOL.
At first, I assigned channel 0 for my some BGMs. and I set-up like this.. 'when BGM on Ch. 0 finish its playback, then Play other BGM.'
Ridiculously, Another BGMs are overlapped with current BGM which is playing now, after other sound effects played.
and, Finally BGMs are Amplified together..! LOL torturing me XD
Of course, I set the BGM as 'music'. not a 'sound effect'. and... Is that sure Music can't be overlapped each other?
I saw that two or more Musics cannot be played at the same time.
but, to me, It is possible. %-S
(I also tried to delete sound resource and remake it. also cleaned Games-generated/my game/music folder. but no works at all)
Is there any problem on 'Channel is done' Event? or... Channel 0 is the problem?
If there is Channel Reservation Command preventing from other sound randomly using that channel, I would maybe solve this...
Maybe if that command will be available later. even though sound effects are exceeded max Channel, we can preserve that channel from playing aborted
-1
I've been stuck on this sound bug for a month now. I try triggering a cheering sound on a win bolean, and it plays it 60 times on start. I try playing it through channels and it only plays in the next scene. I've tried both turning the Sound into a "music" and "sound effect" track, with no luck.
What am i doing wrong here. How do i get a simple cheering sound to trigger on an event?
0
Compared to all other aspects of Stencyl as of this writing, I feel the sound blocks are lacking… like mentioned above in the 'Future' section… please add panning ASAP! Or add/make an extension for FMOD. Thanks for listening.
0
Sound Pitching Features are urgently needed! I think it is not difficult to be added, technically.
That function is required for game which uses Engine sound and Doppler effect.
oooOOOooh man~ I really need it LOL
-1