Jump to content

Loader in Pandajs 2


lars
 Share

Recommended Posts

Hello everyone

I´m having some issues with the Loader in Pandajs 2

When i do the following:

 this.loader.onStart = this.setGame.bind(this);
 this.loader.onComplete = this.loadingGame.bind(this);
 this.loader.start();

    Everything is just fine:

But when I try to make a onProgress the onProgress does not response:

 this.loader.onStart = this.setGame.bind(this);
 this.loader.onProgress = this.processGame.bind(this);
 this.loader.onComplete = this.loadingGame.bind(this);
 this.loader.start();

I can see it, and trace it in the Loader.js class :

onProgress: function() {
 //console.log(this.percent);
//if (this.barFg) this.barFg.scale.x = this.percent / 100;
    }

Her is a simple implementation I done:

game.module(
    'game.start'

)

.require(
     'game.assets'

 )


.body(function() {

    game.createScene('Start', {
        backgroundColor: '#5ca282',

        init: function() {
            
         
  this.loader = new game.Loader();             
            
 this.loader.onStart = this.setGame.bind(this);
 this.loader.onProgress = this.processGame.bind(this);
 this.loader.onComplete = this.loadingGame.bind(this);
 this.loader.start();

  }, //END init

          setGame: function() {
           console.log('started'); 
        },
        
          processGame: function() {
           console.log('percent'); 
        },
        
      
        

        loadingGame: function() {

            document.getElementById('loading').style.display = "none";

            this.startContainer = new game.Container().addTo(this.stage);


            if (!/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
                this.mytastatur = new game.Sprite('tastatur').addTo(this.startContainer);





            } else {

                this.mytastatur = new game.Sprite('uden-tastatur').addTo(this.startContainer);

            }

            this.mytastatur.position.x = game.system.width / 2 - this.mytastatur.width / 2;
            this.mytastatur.position.y = 0;
            this.mytastatur.interactive = true;
            this.mytastatur.click = this.mytastatur.tap = this.changeScene.bind(this, "Main");

        },


        changeScene: function(go) {


            game.system.setScene(go);
            var playbg = game.audio.playMusic('bb', true);
            game.audio.setVolume(playbg, 0.2);

        },




    }) //END Start



});

Anybody knows what wrong with onProgress on the Loader.

/Lars

Link to comment
Share on other sites

Hello Enpu

Yes I have a assets.js which holding the following:

game.module(
    'game.assets'
)
    .body(function() {

        game.addAsset('newgra/tastatur.jpg', 'tastatur');
        game.addAsset('newgra/uden-tastatur.jpg', 'uden-tastatur');
        game.addAsset('newgra/aeggeskilt.png', 'level1');
        game.addAsset('newgra/aeggeskilt.png', 'level2');
        game.addAsset('newgra/aeggeskilt.png', 'level3');

        game.addAsset('newgra/forgrund.png', 'bord');
        game.addAsset('newgra/baggrund.png', 'stribes');
        game.addAsset('newgra/bg-himmel.jpg', 'heaven');
    
        game.addAsset('newgra/baggrund_level1.png', 'baglevel1');
        game.addAsset('newgra/baggrund_level2.png', 'baglevel2');
        game.addAsset('newgra/baggrund_level3.png', 'baglevel3');
     
        game.addAsset('newgra/rabbit.json');

        game.addAsset('newgra/kylling.json');
        game.addAsset('newgra/fox.json');

        game.addAsset('newgra/smallchicken.json');
        game.addAsset('newgra/chickenweapon.json');

        game.addAsset('newgra/eggglow.json');
        game.addAsset('newgra/eggglow_blue.json');
        game.addAsset('newgra/eggglow_purple.json');

        game.addAsset('newgra/plane.json');
        game.addAsset('newgra/cheep.json');
        game.addAsset('newgra/chickenbaloonfly.json');

        game.addAsset('newgra/gennemfoert-lvl1.jpg', 'level1done');
        game.addAsset('newgra/gennemfoert-lvl2.jpg', 'level2done');
        game.addAsset('newgra/gennemfoert-lvl3.jpg', 'level3done');

        game.addAsset('newgra/shitbullet.png', 'bullets');
        game.addAsset('newgra/karamel.png', 'bigagurk');
      

        game.addAsset('newgra/karamel_small.png', 'peachs');
        game.addAsset('newgra/karamel2_small.png', 'peachs2');
        game.addAsset('newgra/karamel3_small.png', 'peachs3');
        game.addAsset('newgra/karamel4_small.png', 'peachs4');
        game.addAsset('newgra/sun.json');

        game.addAsset('newgra/eggs/aeg1-1.png', 'sam1');
        game.addAsset('newgra/eggs/aeg1-2.png', 'sam2');
        game.addAsset('newgra/eggs/aeg1-3.png', 'sam3');
        game.addAsset('newgra/eggs/aeg-2-1.png', 'sam4');
        game.addAsset('newgra/eggs/aeg-2-2.png', 'sam5');
        game.addAsset('newgra/eggs/aeg-2-3.png', 'sam6');
        game.addAsset('newgra/eggs/aeg3-1.png', 'sam7');
        game.addAsset('newgra/eggs/aeg3-2.png', 'sam8');
        game.addAsset('newgra/eggs/aeg3-3.png', 'sam9');

        game.addAsset('newgra/eggs/aeg1-1-mini.png', 'sam1-mini');
        game.addAsset('newgra/eggs/aeg1-2-mini.png', 'sam2-mini');
        game.addAsset('newgra/eggs/aeg1-3-mini.png', 'sam3-mini');
        game.addAsset('newgra/eggs/aeg-2-1-mini.png', 'sam4-mini');
        game.addAsset('newgra/eggs/aeg-2-2-mini.png', 'sam5-mini');
        game.addAsset('newgra/eggs/aeg-2-3-mini.png', 'sam6-mini');
        game.addAsset('newgra/eggs/aeg3-1-mini.png', 'sam7-mini');
        game.addAsset('newgra/eggs/aeg3-2-mini.png', 'sam8-mini');
        game.addAsset('newgra/eggs/aeg3-3-mini.png', 'sam9-mini');

        game.addAsset('newgra/button-left.png', 'jump');
        game.addAsset('newgra/button-right.png', 'shooting');

        game.addAsset('particle.png', 'particle');
        game.addAsset('testfont.fnt');

        game.addAudio('sound/waterdrop.*', 'water');
        game.addAudio('sound/fruit.*', 'fruit');
        game.addAudio('sound/newsound/baggrund_paaskespil.*', 'bb');
        game.addAudio('sound/newsound/baggrund_paaskespil2.*', 'bb2');
        game.addAudio('sound/newsound/baggrund_paaskespil3.*', 'bb3');

        game.addAudio('sound/newsound/Fail_0.*', 'fail0');
        game.addAudio('sound/newsound/Fail_1.*', 'fail1');
        game.addAudio('sound/newsound/Fail_2.*', 'fail2');

        game.addAudio('sound/newsound/done_level1.*', 'goal1');
        game.addAudio('sound/newsound/done_level2.*', 'goal2');
        game.addAudio('sound/newsound/done_level3.*', 'goal3');

        game.addAudio('sound/newsound/first_course.*', 'hint4');

        game.addAudio('sound/newsound/airplane.*', 'airplane');
        game.addAudio('sound/newsound/sheep.*', 'sheepsound');
    
        game.addAudio('sound/newsound/biplane.*', 'biplane');

        game.addAudio('sound/newsound/collectegg.*', 'collectegg');
        game.addAudio('sound/newsound/shoot.*', 'shoot');
        game.addAudio('sound/newsound/shoot1.*', 'shoot1');
        game.addAudio('sound/newsound/shoot2.*', 'shoot2');
    
        game.addAudio('sound/newsound/fanfare.*', 'fanfare');




    });

 

Link to comment
Share on other sites

I have tried with a panda 2 update version from: https://github.com/ekelokorpi/panda-engine/tree/develop/src

And tried the following: 

game.module(
    'game.main'
)
.body(function() {

game.addMedia('baggrund_level1.png','bb');

    
game.createScene('Main', {
    backgroundColor: '#666',

    init: function() {


   console.log('im started');
  this.loader = new game.Loader();
 this.loader.onStart = this.setGame.bind(this);
 this.loader.onProgress = this.setPercentGame.bind(this);
 this.loader.onComplete = this.loadingGame.bind(this);
 this.loader.start();



        
    },

       setGame: function() {
           console.log('Started'); 
        },

         setPercentGame: function() {
           console.log('percent'); 
        },

        loadingGame: function(){
            
        var sprite = new game.Sprite('bb');
        sprite.addTo(this.stage);
 }

 
});

});

With the same result. No response from the onProgress listener. 

Link to comment
Share on other sites

Default loader will load that baggrund_level1.png file before you enter to your Main scene. So that's why there is nothing to load, and onProgress will not be called.

If you want to change the default loader, you can inject game.Loader class, or make new class from it and then change the default loader class into the new one in your config.

Like this:

game.createClass('MyLoader', 'Loader', {
    onStart: function() {},
    onProgress: function() {},
    onComplete: function() {}
});

game.config = {
    system: {
        loader: 'MyLoader'
    }
};

 

Link to comment
Share on other sites

Hello Enpu

So f...... nice to have you back :-) . It´s working now. Thanks a lot ...  

Heres how I did (just a dummy, with some stolen parts), and put a reference in the config.js file as you said :-) :

game.config = {
    system: {
        width: 1024,
        height: 768,
        center: true,
        scale: true,
        loader: 'MyLoader'
    }
};

And the dummy loader: 

game.module(
    'game.main'
)


.require(
    'game.assets'
)

.body(function() {

    this.bar;

    game.createClass('MyLoader', 'Loader', {
        onStart: function() {

            this.bar = new game.Graphics();

            this.bar.beginFill('#ccc');
            this.bar.drawRect(0, 0, 260, 40);

            this.bar.x = game.system.width / 2 - (260 / 2);
            this.bar.y = game.system.height / 2 - (40 / 2);
            this.bar.scale.x = this.percent / 100;
            this.bar.addTo(this.stage);

        },

        onProgress: function() {

            console.log(this.percent);
            //console.log(this.sprite.x);
            this.bar.scale.x = this.percent / 100;

        },

        onComplete: function() {

            game.system.setScene('Main');
        }
    });

    game.createScene('Main', {
        backgroundColor: '#666',

        init: function() {

            console.log('opo');


        }


    });





});

 

Link to comment
Share on other sites

Only one thing:

If I try to preload mp3 like:

 game.addMedia('sound/soundwaterdrop.*', 'water');

Errror: Uncaught Unsupported file format *

or

 game.addMedia('sound/soundwaterdrop.mp3', 'water');

Error: Unsupported file format mp3

 

This happens in the updated 2.0 version: 

https://github.com/ekelokorpi/panda-engine/tree/develop/src

Have been trying to look around in the Loader.js file ... but ... :-)

Link to comment
Share on other sites

  • 2 months later...
game.addMedia('assetfile','assetfilenname')

  So we only use game.addMedia for all asset loading from now on? I used game.addAsset and game.addAudio previously last time I used Panda JS 2.0.

I'm going through the latest panda develop version and just trying to wrap my head around some of the changes.

Something weird happened when I tried loading m4a/ogg audio files though, I enabled retina/hires and it loads all the image and image@2x assets correctly, including fonts. But for some reason it's looking for filename@2x.m4a/ogg for audio files as well. Is this a bug?

game.addMedia('sound/sound_sfx.m4a','sound_fx');


Cheers

Link to comment
Share on other sites

  • 4 weeks later...
On 6/16/2017 at 2:54 AM, zakhov said:

game.addMedia('assetfile','assetfilenname')

  So we only use game.addMedia for all asset loading from now on? I used game.addAsset and game.addAudio previously last time I used Panda JS 2.0.

I'm going through the latest panda develop version and just trying to wrap my head around some of the changes.

Something weird happened when I tried loading m4a/ogg audio files though, I enabled retina/hires and it loads all the image and image@2x assets correctly, including fonts. But for some reason it's looking for filename@2x.m4a/ogg for audio files as well. Is this a bug?


game.addMedia('sound/sound_sfx.m4a','sound_fx');


Cheers

Nevermind, fixed it myself. I just added a workaround to check for the audio formats at the getfile funciton in loader.js and ignore them even if retina | hires is enabled. 

Cheers

Link to comment
Share on other sites

  • 3 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...