Advertisement
Guest User

Untitled

a guest
Aug 7th, 2014
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haxe 2.12 KB | None | 0 0
  1. package ;
  2. import flixel.FlxG;
  3. import flixel.math.FlxRandom;
  4. import motion.Actuate;
  5. import openfl.Assets;
  6. import openfl.events.Event;
  7. import openfl.media.Sound;
  8. import openfl.media.SoundChannel;
  9. import openfl.media.SoundTransform;
  10.  
  11. /**
  12.  * ...
  13.  * @author MintPaw
  14.  */
  15. class Sm
  16. {
  17.     private static var _musicChannel:SoundChannel;
  18.     private static var _musicVolume:Float = 1;
  19.    
  20.     public static var ORB:String = "music/orb";
  21.     public static var DIE:String = "music/die";
  22.     public static var SCREEN:String = "music/screen";
  23.    
  24.     public function new()
  25.     {
  26.        
  27.     }
  28.    
  29.     public static function init():Void
  30.     {
  31.         FlxG.stage.addEventListener(Event.ENTER_FRAME, update);
  32.     }
  33.    
  34.     public static function playMenuMusic():Void
  35.     {
  36.         if (_musicChannel != null) _musicChannel.stop();
  37.        
  38.         #if (mobile || desktop)
  39.             var music:Sound = Assets.getSound("music/menu compressed.wav");
  40.         #else
  41.             var music:Sound = Assets.getSound("music/menu compressed.mp3");
  42.         #end
  43.        
  44.         _musicChannel = music.play(0, 99999);
  45.         _musicVolume = 0;
  46.        
  47.         Actuate.tween(Sm, 2, { _musicVolume: 1 } );
  48.     }
  49.    
  50.     public static function menuToGameMusic():Void { Actuate.tween(Sm, 2, { _musicVolume: 0 } ).onComplete(Sm.playGameMusic, []); }
  51.     public static function gameToMenuMusic():Void { Actuate.tween(Sm, 2, { _musicVolume: 0 } ).onComplete(Sm.playMenuMusic, []); }
  52.    
  53.     private static function update(e:Event):Void
  54.     {
  55.         if (_musicChannel == null) return;
  56.        
  57.         var t:SoundTransform = new SoundTransform();
  58.         t.volume = _musicVolume;
  59.        
  60.         _musicChannel.soundTransform = t;
  61.     }
  62.    
  63.     public static function playGameMusic():Void
  64.     {
  65.         if (_musicChannel != null) _musicChannel.stop();
  66.        
  67.         #if (mobile||desktop)
  68.             var music:Sound = Assets.getSound("music/game compressed.wav");
  69.         #else
  70.             var music:Sound = Assets.getSound("music/game compressed.mp3");
  71.         #end
  72.        
  73.         _musicChannel = music.play(0, 99999);
  74.         _musicVolume = 0;
  75.        
  76.         Actuate.tween(Sm, 2, { _musicVolume: 1 } );
  77.     }
  78.    
  79.     public static function playEffect(id:String):Void
  80.     {
  81.         #if (mobile||desktop)
  82.             Assets.getSound(id + ".wav").play();
  83.         #else
  84.             Assets.getSound(id + ".mp3").play();
  85.         #end
  86.     }
  87.    
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement