Username or E-mail
Password (Forgot?)
New? Sign Up
Join or Sign In
Forums Stencylpedia Stencyl TV Translations Go Pro - Plans & Pricing Download Stencyl


Switch to Book Layout

1: Getting Started

  • Getting Started
  • Crash Course
  • Crash Course 2
  • StencylForge

2: Building Logic

  • What is a Behavior?
  • Creating a Behavior
  • Attributes
  • Game Attributes
  • Attribute Types
  • Events
  • Our Behaviors

3: Actors

  • What are Actors?
  • Animations
  • Motion & Forces
  • Physics
  • Controls
  • Collisions & Groups
  • Killing vs. Recycling
  • Tweening
  • Effects
  • Chapter 3 Challenge

4: Scenes

  • Scene Basics
  • The Camera
  • Tilesets
  • Regions
  • Drawing Text & HUDs
  • Changing Scenes
  • Music, Sounds & Channels
  • Backgrounds
  • Customizing Actors
  • Chapter 4 Challenge

5: Game Mechanics

  • Saving
  • Pausing
  • 3rd Party Services
  • Web Requests

6: Advanced Topics

  • Get/Set Attributes
  • Custom Events
  • Blending Modes
  • Lists
  • Custom Blocks
  • Continuous Collisions

7: Testing & Tuning

  • Testing Games
  • Optimizing Performance 1
  • Optimizing Performance 2

8: The Last 10%

  • Flash Publishing
  • Standalone Apps
  • iOS App Store
  • Chrome Store
  • Making Money

M1: Mobile - Intro

  • Getting Started
  • Testing on your Device
  • Flash -> iOS Guide

M2: Mobile - Basics

  • Atlases
  • Drawing Text
  • Retina Display
  • Accelerometer
  • Joystick
  • Universal Games

M3: Mobile - Services

  • iAds
  • Game Center
  • In-App Purchases

M4: Mobile - Publishing

  • Debugging
  • Publishing to the App Store
  • Optimizing Performance
  • Promoting your Game

A: Troubleshooting

  • Showstoppers
  • General FAQ
  • iOS FAQ
  • The 90% Memory Warning
  • Recovering Broken Games
  • Can't Export to SWF
  • Reloading Documents
  • Generating Logs
  • Flash Security Settings
  • How to Report Bugs

B: How-To Guides

  • Importing Assets
  • Scene Designer
  • Code Mode
  • Font Editor
  • Pencyl (Image Editor)
  • Tile Editor (Shapes)
  • Game Cleaner

C: Reference

  • Glossary
  • Block Reference
  • Useful Shortcuts
  • Stencyl API

D: Resources

  • Stencyl TV
  • Abigayl's Guides
  • Giving Critiques
  • Creating Extensions
  • Translating Stencyl
  • Credits

3.0 Drafts (In Progress)

  • What's New in Stencyl 3.0?
  • Setup (Android)
  • Setup (Desktop)
  • Setup (iOS) - Concepts
  • Setup (iOS) - Mac
  • Setup (iOS) - Windows
  • Testing iOS on Windows
  • iOS Troubleshooter

  • Mobile App Scaling
  • Full Screen Mode
  • Simple Physics
  • Backgrounding an App

  • iOS App Store
  • Mac App Store
  • Windows Store
  • Google Play
  • HTML5

  • Android Ads
  • Android Purchases (WIP)
  • 4" Form Factor (iPhone 5)
  • Mobile Input
  • Mobile Features

  • Extending the Engine
  • iOS / Android Extensions
  • Developing the Official Extensions
  • Developing the Engine

  • iAds (Revised)
  • Game Center (Revised)
  • iOS Purchases (Revised)
  • Atlases (Revised)
  • Drawing Text (Revised)
  • Joystick (Revised)
  • Accelerometer (Revised)
  • Sounds (Revised, WIP)
  • Debugging (Revised, WIP)
  • iOS Performance (Revised)
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!
3 Comments
afabello
I've had troubles with playing music for one of my scenes. The music doesn't play but my sound effects does. Ever since i added the camera scroll, my background music hasn't worked.
Help!

0 8 months, 3 weeks ago
Rexasul
Oops, remove that space in the link.
0 1 year, 1 month ago
Rexasul
I'm that user :) and here is my vague attempt at boiling it down. http://shadowlabs.net/stencyldocs/s eamlessmp3.pdf
0 1 year, 1 month ago



Commenting Guidelines

Sign In to Comment

Make Games

  • What is Stencyl?
  • Roadmap
  • Pricing

Play

  • Arcade
  • Showcase

Community

  • Forums
  • Chat
  • Translations

Help

  • Stencylpedia
  • Stencyl TV

About Us

  • Blog
  • Contact Us
  • Press
  • Privacy
Follow Stencyl on Twitter



© 2013 Stencyl, LLC.