Jump to content

Black Screen before Preloader ( game.load.progress always at 0)


vastron
 Share

Recommended Posts

Hello everyone. The problem is I want to immediately
display the loading screen. I don't want to see a black screen before the loading screen.I followed the example shown in phaser.io,
http://examples.phaser.io/_site/view_full.html?d=loader&f=load+events.js&t=load events,
but the loading progress always remains at 0. I can't figure out what the problem is.
Can you help me?

my boot state looks like this

 init: function () {
        game.stage.backgroundColor = "#012358";
        game.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL;
        game.scale.pageAlignHorizontally = true;
        game.scale.pageAlignVertically = true;
    },
    preload: function () {
        atlas = game.load.atlas('mysprites', 'im/sprites.png', 'im/spritesJson.json');
        game.load.spritesheet('anim', 'im/myloaderSheet.png', (animationFrameWidth + spaceBetweenFrames), animationFrameHeight, 30);
    },
    create: function () {       
        game.state.start('Loading');
    }

and my loading state looks like this

 preload: function () {
        game.load.json('txts', 'scripts/text.json');
        game.load.script('webfont', 'https://ajax.googleapis.com/ajax/libs/webfont/1.4.7/webfont.js');
        game.load.start();
    },
create: function () {
        myTxts = game.cache.getJSON('txts');       
        bg = game.add.tileSprite(0, 0, 1280, 720, 'mysprites');
        bg.frameName = "bg";
        animation = game.add.sprite((game.world.centerX - 25), (game.world.centerY - 50), 'animation');
        loadingBar = new Phaser.Rectangle(game.world.centerX, spriteY, 10, 3);
        anim.animations.add('playAnim', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], true);
        anim.animations.play(playAnim', frameRate, true);     
        game.load.onLoadStart.add(loadStart, this);
        game.load.onFileComplete.add(fileComplete, this);
        game.load.onLoadComplete.add(loadComplete, this);

    },
    update: function () {
        loadingBar.inflate(1, 0);
        console.log(game.load.progress);
    },
    render: function () {
        game.debug.geom(loadingBar, '#FFFFFF');
    }

function loadStart() {
    console.log('Loading');
}

function fileComplete(progress, cacheKey, success, totalLoaded, totalFiles) {
    console.log("File Complete: " + progress + "% - " + totalLoaded + " out of " + totalFiles);
    loaded = true;

}

function loadComplete() {
    if (loaded) {
        changeState("Level 1");
        loaded = false;
    }

}

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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