SoundLiteAS3

author:
Rajavanya Subramaniyan
description:
Add all sound related functionality within minutes to your game.
lastupdate:
2013-09-16
tag:
sound, music, bg, sfx, muting, fading, soundgroups
homepage:
https://github.com/quakeboy/SoundLiteAS3
author-website:
http://www.rajavanya.com

Why SoundLite?

SoundLiteAS3 is the result of thinking why does a game developer need to code certain game sound related tasks again and again, even though they are simple.

For your game it allows very quick integration of features like

  • BG and SFX mute options.
  • Having a set of SFX sounds and playing them RANDOMLY or SEQUENTIALLY.
  • Allows setting volume levels for individual sounds
  • Fading In and Out of Background music when scene changes.

Limitations

  • It can deal with Embedded Sound objects or the ones which are preloaded only, targeted at common flash games.
  • Doesn't bother with panning controls.

How to use?

  • First preload your sounds in AS3 “Sound” objects either via embedding or other methods.
  • Create MSound and MSoundGroup objects as needed for all your sounds
  • Call MBG.init() and MSFX.init() always in the beginning
  • Use MSFX.play() or MBG.play() methods and pass MSound objects.
  • MSFX and MBG has methods to control muting of SFX and BG sounds

Notes

  • Alternatively you can use the MSound and MSoundGroup objects directly as well and call methods on their objects.
  • MBG and MSFX has static methods, so no need to create objects
  • Every class has “cleanUp()” method which sets all references it uses to null

Example usage - simple

//first declare the Embeds
[Embed(source="../res/loop.mp3")]
public static var bg_loop:Class;
 
[Embed(source="../res/sfx.mp3")]
public static var sfx_1:Class;
 
//create MSound objects
private var sfx1:MSound = new MSound(new sfx_1());
private var bgloop:MSound = new MSound(new bg_loop(), 1000, 0.4);
 
//init MBG and MSFX, preferably in AS3 main class constructor
MBG.init();
MSFX.init();
 
//use the methods on events as needed
MSFX.play(sfx1);
MBG.play(bgloop);   //fadesIn, when done through MBG
MBG.stop();         //fadesOut, when done through MBG
MBG.toggleMute();   //stop and starts last sound automatically when done on MBG
MSFX.setMute(true);

Example usage - sound groups

//gem0 to gem4 are MSound objects
private var allgems:Array = new Array(gem0, gem1, gem2, gem3, gem4);
private var gems_random:MSoundGroup = new MSoundGroup(allgems);
private var gems_sequential:MSoundGroup = new MSoundGroup(allgems, MSoundGroup.MODE_SEQUENTIAL);

//to play
MSFX.play(gems_random); //or
MSFX.play(gems_sequential);

Changelog

  • 2013/09/25 17:08: First public version

dfsdaf asdfsdafsafad的法师的Boldsdaf Textd 打发打发士大夫对方啊对方

  extensions/soundliteas3.txt · Last modified: 2015/12/01 08:43 by 101.231.32.166
 
Powered by DokuWiki