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 DaveVoyles

I’m trying to load music files for my Impact game, but I can’t figure out what I’m doing wrong here. I want a different song for each screen, so I load the individual song on the screen it belongs to, then select play for that song.

Problem is, whenever a new screen loads, it just restarts the song that was already playing!

Here is my current workaround, which isn’t too elegant, and just has me calling ig.music.next(); for each screen.

    .defines(function () {

        StartScreen = ig.Game.extend({

            stage39Music: new ig.Sound('media/Music/Stage 39.mp3, true'),
            stage39Music: new ig.Sound('media/Music/Stage 39.ogg, true'),
            stage39Music: new ig.Sound('media/Music/Stage 39.*, true'),
            init: function () {

]
              
                // Loads music, then begins to play track
                ig.music.add(this.stage39Music);
                ig.music.next();
               // ig.music.play(this.stage39Music);

MyGame = ig.Game.extend({

            stage50Music: new ig.Sound('media/Music/Stage 50.mp3', true),
            stage50Music: new ig.Sound('media/Music/Stage 50.ogg', true),
            stage50Music: new ig.Sound('media/Music/Stage 50.*', true),


            /*******************************************
             * Initialization
             ******************************************/
            init: function () {

                // Loads music, then begins to play track
                ig.music.add(this.stage50Music);
                ig.music.next();
                ig.music.loop = true;

 
       /*******************************************
        * CREDITS SCREEN
        *******************************************/
        StaffRollScreen = ig.Game.extend({
            staffRollMusic: new ig.Sound('media/Music/Staff Roll 1.mp3, Staff Roll 1', true),
            staffRollMusic: new ig.Sound('media/Music/Staff Roll 1.ogg, Staff Roll 1', true),
            staffRollMusic: new ig.Sound('media/Music/Staff Roll 1.*, Staff Roll 1', true),

            init: function () {
                // Loads music, then begins to play track
                ig.music.add(this.staffRollMusic);
                //  ig.music.play(this.staffRollMusic);
                ig.music.next();

1 decade ago by Joncom

Why not add all songs at the same time?

ig.music.add(this.stage50Music, 'track1');
ig.music.add(this.stage51Music, 'track2');
ig.music.add(this.stage52Music, 'track3');

And then just call ig.music.play('track1'); or whichever track you'd like?
Should play the correct track that way...

1 decade ago by DaveVoyles

I was trying to break up how much is being loaded throughout each screen. But if this works, then I'll definitely try it.

Does Impact forget the other songs that are loaded into memory once a new screen starts? Is that why I'm having this issue?

1 decade ago by DaveVoyles

I figured it out. You need to pass in the second parameter during add as a string.

Then under play, you call that string.

Odd, because the first time you load music, you do NOT need to do this. Only after the first time.

            staffRollMusic: new ig.Sound('media/Music/Staff Roll 1.mp3, Staff Roll 1'),
            staffRollMusic: new ig.Sound('media/Music/Staff Roll 1.ogg, Staff Roll 1'),
            staffRollMusic: new ig.Sound('media/Music/Staff Roll 1.*, Staff Roll 1'),

            init: function () {
                // Loads music, then begins to play track
                ig.music.add(staffRollMusic, 'staffRollMusic');
                ig.music.play('staffRollMusic');

1 decade ago by Joncom

// First of all, ig.Sound does not take a second argument.
// So the string 'Staff Roll 1' does not belong there.

// Fixed.
staffRollMusic: new ig.Sound('media/Music/Staff Roll 1.mp3'),
staffRollMusic: new ig.Sound('media/Music/Staff Roll 1.ogg'),
staffRollMusic: new ig.Sound('media/Music/Staff Roll 1.*'),

// Additionally, the above three lines all do the exact same thing!
// No need for this, just use one line instead.

// Fixed.
staffRollMusic: new ig.Sound('media/Music/Staff Roll 1.*'),

1 decade ago by DaveVoyles

I'm just seeing this now, Joncom.

Thank you for taking the time to help!
Page 1 of 1
« first « previous next › last »