Author Topic: FlxFlod, an encapsulated wrapper class for Flod mod player  (Read 2487 times)

Titch

  • Contributor
  • ****
  • Posts: 270
  • Karma: +0/-0
  • Thing with the guy in the place.
    • View Profile
Since I went to all the effort of getting Mod files to work in Level Up! I though I would share the love. Obviously you'll need to get Flod in order for the FlxFlod wrapper to work. It works just like anything in FlxG would, only you write FlxFlod.setMusic() instead of FlxG. It doesn't yet have -all- the functionality of the Flixel music handling, but it does tie itself up with the built in volume controls, so altering music volume, master volume and mute all effect the mod output in real time.

Code: [Select]
package com.adamatomic.flixel
{
import com.neoart.flod.ModProcessor;
import flash.utils.ByteArray;
import flash.events.KeyboardEvent;
import flash.media.SoundTransform;

/**
* ...
* @author Duncan Saunders 2009
* Distributed under the "I don't really care because I only spent a few hours on this"
* lisence.
*/
public class FlxFlod extends FlxCore
{
private static var _modProcessor:ModProcessor;
private static var _soundTransform:SoundTransform;

public static function setMusic (mod:Class,looping:Boolean=true,autoplay:Boolean = true):void
{
FlxG.log("-----+ FlxFlod v0.3 +----");
if (_modProcessor == null)
{
FlxG.state.stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
_soundTransform = new SoundTransform ();
_modProcessor = new ModProcessor ();
}
else
{
_modProcessor.stop();
}
stop();
_modProcessor.load(new mod as ByteArray, true );
_modProcessor.loopSong = looping;
play();
updateVolume();
}

public static function play ():void
{
_modProcessor.play();
}

public static function pause ():void
{
_modProcessor.pause();
}

public static function stop ():void
{
if (_modProcessor != null)
{
FlxG.state.stage.removeEventListener(KeyboardEvent.KEY_UP, onKeyUp);
_modProcessor.stop();
}
}

private static function onKeyUp(event:KeyboardEvent):void
{
var code:String = String.fromCharCode(event.charCode);
if ((code == '0') || (code == ')') || (code == '-') || (code == '_') || (code == '+') || (code == '=')) {
    if (_modProcessor.song != null) updateVolume();
   }
}

private static function updateVolume ():void
{
_soundTransform.volume = FlxG.getMusicVolume() * FlxG.getMasterVolume() * int(!FlxG.getMute())
FlxG.log("volume set");
if (_modProcessor.song != null) _modProcessor.soundChannel.soundTransform = _soundTransform;
}
}

}

It's a bit hacky, but best to share these things than keep them to yourself, eh?
« Last Edit: Sat, Oct 3, 2009 by Titch »
Free cake whippings every day at #flixel on irc.freenode.net.

nitram_cero (2bam)

  • Contributor
  • ****
  • Posts: 484
  • Karma: +0/-0
    • View Profile
    • 2BAM
This is Badass ;D Thanks for sharing man!
If I have a music-intensive game I'll give it a shot without doubt.

Regards

vonWolfehaus

  • Active Member
  • ***
  • Posts: 247
  • Karma: +0/-0
    • View Profile
    • Cold Constructs
NICE. I didn't know what Flod was, so in anyone is wondering as well, check this page out.
Meet Obama every day at #flixel on irc.freenode.net.
Use your favorite IRC client or  http://webchat.freenode.net/

Mr Dumle

  • Guest
Great job! But you can't use this commercially right? :/

Titch

  • Contributor
  • ****
  • Posts: 270
  • Karma: +0/-0
  • Thing with the guy in the place.
    • View Profile
Flod is covered by a standard CC Attribution-Noncommercial-Share Alike.

This is NORMALLY to prevent people from modifying the source code and selling it. Somehow I don't think the creator of Flod is going to be heavily opposed to people developing small flash games using it. I'll probably be in touch with them soon, so I'll let you know.
Free cake whippings every day at #flixel on irc.freenode.net.

nitram_cero (2bam)

  • Contributor
  • ****
  • Posts: 484
  • Karma: +0/-0
    • View Profile
    • 2BAM
The Non commercial part is quite clear though... :(

axcho

  • Active Member
  • ***
  • Posts: 174
  • Karma: +0/-0
    • View Profile
    • Evolution Live!
There is a completely free alternative, 8BitBoy.

I hear the performance isn't quite as efficient, but I'd say it's probably the best choice for commercial games.

Update:
Oops! Fixed the link.
« Last Edit: Thu, Oct 8, 2009 by axcho »

SeiferTim

  • Contributor
  • ****
  • Posts: 253
  • Karma: +0/-0
    • View Profile
    • Tim's World
Corrected link

Titch

  • Contributor
  • ****
  • Posts: 270
  • Karma: +0/-0
  • Thing with the guy in the place.
    • View Profile
Well I sent an email to the creator of Flod about the lisence. I'll let you guys know when/if I get something back. Probably start a wrapper for 8bitBoy just in case I don't.
Free cake whippings every day at #flixel on irc.freenode.net.

Titch

  • Contributor
  • ****
  • Posts: 270
  • Karma: +0/-0
  • Thing with the guy in the place.
    • View Profile
Excuse the double post. I got an email back this morning. The Flod page has been update with a commercial license that is a steal $5 (paid in donations).
Free cake whippings every day at #flixel on irc.freenode.net.