Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

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:

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() ? )

1 decade ago by dominic

I don&039;t get it. Why don't you just use #ig.music?

init: function(){	
	ig.music.add( this.BGM_001 );
	ig.music.add( this.BGM_002 );
	ig.music.add( this.BGM_003 );
	ig.music.add( this.BGM_004 );
	ig.music.add( this.BGM_005 );
	ig.music.play();
}

Technically, it&039;s not a problem that you create your own instance of #ig.Music, but you shouldn't really need to do that.

Creating another ig.SoundManager instance will have no effect at all. ig.Music and ig.Sound are directly working with the instance at ig.soundManager.

Also, you&039;re calling your #ig.MusicManager&039;s #init() function twice.
this.myMusicManager = new ig.MusicManager(); // first call to init()
this.myMusicManager.init(); // second call to init()

The init() method of a class is always called when instantiating it - see the documentation for ig.Class.

1 decade ago by FelipeBudinich

this.myMusicManager.init();

Seems that this mistake was giving me grief, I removed that line, and now it works like it's supposed to do without the weird workaround that I had built with the new Music() and SoundManager() instances.

Thanks for the reply Dominic!
Page 1 of 1
« first « previous next › last »