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 JackImpact

Hi All,

Anyone has tried to put different music for different levels? I have tried without success following the documentation. My code is as below

ig.musicBgs=new ig.Music();
		
		ig.musicBgs.add('media/sounds/PARK_LEVEL_BACKGROUND.*','a');
		
		ig.musicBgs.add('media/sounds/BEACH_LEVEL_LOOP.*','b');
		ig.musicBgs.add('media/sounds/UNDERWATER_BACKGROUND.*','c' );
		ig.musicBgs.add('media/sounds/SPACE_LEVEL_BACKGROUND.*','d');
		
		
		ig.musicBgs.volume=0.7;
		
		ig.musicBgs.play('b');

My game throwed an error as below

INVALID_STATE_ERR: DOM Exception 11: An attempt was made to use an object that is not, or is no longer, usable.

anyone knows how to play the named track in specific level? The documentation didn't provide working examples.

Thanks for your help in advance!

Jack

1 decade ago by dmen

I have it working though a bit differently - I just add trakcs to ig.Music instead of trying to make an instance of it first... like so:

ig.music.add(new ig.Sound('media/music/bgsound_l1.*'), "l1");
ig.music.add(new ig.Sound('media/music/bgsound_l2.*'), "l2");
ig.music.add(new ig.Sound('media/music/bgsound_l3.*'), "l3");
ig.music.loop = true;
ig.music.volume = .5;
ig.music.play("l1");

1 decade ago by KenD

Yeah, ig.music (lowercase &039;m') is created for you when you call #ig.main() though I'm not sure there's any reason you can't create an instance manually? Best bet is to do as dmen suggests, though.

1 decade ago by JackImpact

tried Dmen's approach...still not working for me!

Worked out another approach-using ig.Sound

declare the sounds in the main.js

musicPark:new ig.Sound('media/sounds/PARK_LEVEL_BACKGROUND.*'),
	musicBeach:new ig.Sound('media/sounds/BEACH_LEVEL_LOOP.*'),

then in the update


if(this.myDirector.currentLevel==0){
	
		this.musicPark.play();
		this.musicSpace.stop();}

if(this.myDirector.currentLevel==1){
	
		this.musicPark.stop();
		this.musicSpace.play();}


not elegant but works!

better alternative is welcome. The impactjs documentation is too brief to use.

1 decade ago by dominic

As suggested, you don&039;t need to create your own #ig.Music instance; use the one that&039;s already provided. See the <1>. I.e. in your Game's #init(), you can just call ig.music.add('track.*').

That said, I&039;m not sure what went wrong with your code. You still _can_ create your own #ig.Music instance if you want to.

Also make sure your sound files are loaded by the pre-loader. See this article and have a look at the code example at the very bottom.

1 decade ago by jeffreycheng

Hi good people using ImpactJS! I'm having troubles with knowing the current level in use.
I understand that we use the .play() method in update but I don't know how to track the current level so I could use a different music for the next level.

I can't seem to use the myDirector and currentLevel as shown above by JackImpact.

Please help
Page 1 of 1
« first « previous next › last »