Jump to content

preload bar image messed up


Chupup Games
 Share

Recommended Posts

I want a preload bar from an png image i created, but the image is kind of messed up, the

only thing the actual bar has in common with my image is the color.

 

i use this code with phaser 1.2:

 

var loader_state = {

 

preloadBar: Phaser.Sprite,

 

preload: function () {

this.preloadBar = game.add.sprite(96, 144, 'preload');

        game.load.setPreloadSprite(this.preloadBar, 0);

 

..........

Link to comment
Share on other sites

Yes, here is a screenshot of how it should look:

 

preload_bar.png

 

and here how it actually looks:

 

loadbar_messed.png

 

the code:

// Initialize Phaser and create a 480x320px gamevar game = new Phaser.Game(480, 320, Phaser.AUTO, 'stage');var player;var starfield_1;var starfield_2;var starfield_3;// Create a new 'boot' state that will doing some pre-setupvar boot_state = {    preload: function () {        game.load.image('preload', 'assets/preload_bar.png');    },    create: function () {        // Because Multitouch isn't needed the maxPointer is set to 1        game.input.maxPointers = 1;        //  Phaser will automatically pause if the browser tab the game is in loses focus. You can disable that here:        this.stage.disableVisibilityChange = true;        game.stage.backgroundColor = '#000000';        game.scale.minWidth = 480;        game.scale.minHeight = 320;        game.scale.maxWidth = 960;        game.scale.maxHeight = 640;        game.scale.forceLandscape = true;        game.scale.pageAlignHorizontally = true;        game.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL;        game.scale.setShowAll();        game.scale.refresh();        game.state.start('loader');    }};// Create a new 'loader' state that will load all assetsvar loader_state = {    preloadBar: Phaser.Sprite,    preload: function () {        //  Set-up the preloader sprite        this.preloadBar = game.add.sprite(96, 144, 'preload');        game.load.setPreloadSprite(this.preloadBar, 0);        game.load.image('instructions', 'assets/instructions.png');        game.load.spritesheet('starfield', 'assets/starfield.png', 960, 320, 3);        game.load.atlas('tiles', 'assets/tiles.png', 'assets/tiles.json');    },    create: function () {        //game.state.start('menu');    }};
Link to comment
Share on other sites

I just upgraded to 2.0 and my preload bar doesn't even appear, here's the main code if anyone wants to take a look:

preloadBar: Phaser.Sprite;loadingText: Phaser.Text;        preload() {            //Preload bar and Loading text            this.loadingText = this.add.text(this.world.centerX, this.world.centerY - ((this.world.height / 2) / 2), "Loading", { font: "36px Chunk", fill: "#ffffff", align: "center" });            this.loadingText.anchor.set(0.5, 0.5);            this.preloadBar = this.add.sprite(this.game.world.centerX, this.game.world.centerY, 'preloadBar');            this.preloadBar.anchor.setTo(0.5, 0.5);            this.load.setPreloadSprite(this.preloadBar);        }        create() {            //Draw loaded text            this.loadingText.setText("Loaded");            this.loadingText.anchor.set(0.5, 0.5);            //Animate loaded text            this.add.tween(this.loadingText).to({ alpha: 0 }, 1000, Phaser.Easing.Exponential.In, true);            //Animate preload bar up...            this.add.tween(this.preloadBar).to({ alpha: 0 }, 1000, Phaser.Easing.Exponential.In, true);            var tween = this.add.tween(this.preloadBar).to({ y: (this.game.canvas.height / 2) }, 1000, Phaser.Easing.Exponential.In, true);            tween.onComplete.add(this.startLevel, this);        }
Link to comment
Share on other sites

Same with me (It has been around for 4 weeks).

I have a boot state which preloads the Preloader state sprite sheet (logo+100% width bar).  I know my assets are loaded and I can see my logo/bar. 

But when I pass the bar to the PreloadSprite then I no longer see the bar. 

Link to comment
Share on other sites

I had the same problem with this.load.setPreloadSprite() as well. Here is my workaround:

//this.load.setPreloadSprite(preloadFill);//load assetsthis.load.onFileComplete.add(this.loadProgress, this);loadProgress:function(progress){	this.preloadFill.scale.x = progress/100;	this.preloadPointer.x = this.preloadBg.x + progress/100 * this.preloadBg.width;}

I'm not sure how setPreloadSprite is working as it never worked for me when I tried in 2.0. I assume it utilizes masking. For me scaling works and is enough.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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