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

10 years ago by BrownHorse

I have a class that creates the sound objects. Then I create an instance of the class in my main.

Here is the module that creates the sound objects:
ig.module(
    'game.note-sounds'
)
.defines(function(){

ig.NoteSounds = ig.Class.extend({
    guitar: null,
    trumpet: null,
    xylo: null,
    piano: null,

    fileNames: [
        '_a1.*','_a2.*','_a3.*','_a4.*','_as1.*','_as2.*','_as3.*','_as4.*',
        '_b1.*','_b2.*','_b3.*','_b4.*',
        '_c1.*','_c2.*', '_c3.*','_c4.*','_c5.*','_cs1.*','_cs2.*', '_cs3.*','_cs4.*',
        '_d1.*','_d2.*','_d3.*', '_d4.*','_ds1.*','_ds2.*','_ds3.*','_ds4.*',
        '_e1.*','_e2.*','_e3.*','_e4.*',
        '_f1.*','_f2.*','_f3.*','_f4.*','_fs1.*','_fs2.*','_fs3.*','_fs4.*',
        '_g1.*','_g2.*','_g3.*','_g4.*','_gs1.*','_gs2.*','_gs3.*','_gs4.*',
    ],

    init: function(){
        this.guitar = this.createArray("guitar", "g");
        this.trumpet = this.createArray("trumpet", "t");
        this.xylo = this.createArray("xylophone", "x");
        this.piano = this.createArray("piano", "p");
    },

    createArray: function(name, letter){
        var array = [];
        var path = "media/sounds/" + name + "/" + letter;

        for(i = 0; i < this.fileNames.length; i++){
            array[i] = new ig.Sound(path + this.fileNames[i]);
        }
        return array;
    },

});
    
});

And here is the beginning of my main:
ig.module( 
	'game.main' 
)
.requires(
	'impact.game',
	'impact.font',
	
	'game.levels.wave1',
	'game.levels.wave2',
	'game.levels.wave3',
	
	'game.note-sounds',
	'game.song-handler'
)
.defines(function(){

GameScreen = ig.Game.extend({

	noteBank: new ig.NoteSounds(), 


I believe I am pre-loading the sounds since I can add a print statement to the end of 'init' in the 'note-sounds' module and it will print during the loading screen.

10 years ago by Joncom

No, they are not being pre-loaded.
init is called after all resources have been loaded.
You are loading the audio "on the fly" so to speak.

10 years ago by BrownHorse

So they're not being preloaded even though I create the NoteSounds object before the init function in my main?

10 years ago by Joncom

Hmm. On second thought, I'm not so sure.

The way you&039;re creating an instance of #ig.NoteSounds implies that its init will be called during the pre-loader. Therefore the sounds will at least start loading.

Hmmm... If I had to guess, I&039;d say you found a neat way to pre-load via the #init function.

Confirmation would be nice though...
Page 1 of 1
« first « previous next › last »