1 decade ago by FelipeBudinich
Hello Everyone!
I'm currently making a pretty big game, so I've got a lot of different background songs. The thing is that I don't want to write all the music management stuff on my main.js because it could get messy pretty fast, so i've been trying to encapsulate all of it onto another class.
Currently I'm doing this, on main.js:
and then on musicmanager.js (the class I created):
My problem is that, in order to make it work, I'm creating a new ig.SoundManager() and a new ig.Music().
Is there a way to access the ig.Music() and ig.SoundManager() that are automatically created at ig.music by the ig.main() function?
( Or, does it matter that I don't? would it have an impact on performance if I've got two SoundManager() and two Music() ? )
I'm currently making a pretty big game, so I've got a lot of different background songs. The thing is that I don't want to write all the music management stuff on my main.js because it could get messy pretty fast, so i've been trying to encapsulate all of it onto another class.
Currently I'm doing this, on main.js:
ig.module( 'game.main' ) .requires( 'utils.splash-loader', 'impact.game', 'impact.font', 'game.musicmanager' ) .defines(function(){ MyGame = ig.Game.extend({ init: function() { this.myMusicManager = new ig.MusicManager(); this.myMusicManager.init(); }, update: function() { this.myMusicManager.update(); this.parent(); }, draw: function() { this.parent(); } }); ig.main( '#canvas', MyGame, 60, 1024, 712, 1, ig.SplashLoader ); });
and then on musicmanager.js (the class I created):
ig.module( 'game.musicmanager' ) .requires( 'impact.sound' ) .defines(function(){ ig.MusicManager = ig.Class.extend({ BGM_001 : new ig.Sound( 'media/snd/music/02.*', false ), BGM_002 : new ig.Sound( 'media/snd/music/01.*', false ), BGM_003 : new ig.Sound( 'media/snd/music/03.*', false ), BGM_004 : new ig.Sound( 'media/snd/music/04.*', false ), BGM_005 : new ig.Sound( 'media/snd/music/05.*', false ), init: function(){ //music ig.soundMngr = new ig.SoundManager(); ig.msc = new ig.Music(); ig.msc.add( this.BGM_001 ); ig.msc.add( this.BGM_002 ); ig.msc.add( this.BGM_003 ); ig.msc.add( this.BGM_004 ); ig.msc.add( this.BGM_005 ); ig.msc.play(); }, update: function(){ //do stuff }, }); });
My problem is that, in order to make it work, I'm creating a new ig.SoundManager() and a new ig.Music().
Is there a way to access the ig.Music() and ig.SoundManager() that are automatically created at ig.music by the ig.main() function?
( Or, does it matter that I don't? would it have an impact on performance if I've got two SoundManager() and two Music() ? )