Jump to content

loadTexture slow the game


odelia
 Share

Recommended Posts

I have a sprite with a sprite sheet and it works find, but when i change the texture of the sprite to a different sprite sheet it pause the whole game for a second...

why is that???

 

this.item = this.game.add.sprite(0,0,"mainCharacter");
this.item.anchor.set(0.5);

function foundItem(){
	this.item.loadTexture("mainCharacterFound", 0);
}

 

Link to comment
Share on other sites

This is running under WebGL, yes? Because it's most likely the time it takes to upload the texture to the GPU that is causing the lag. If the texture is especially large you'll certainly notice this (or the GPU is old). To avoid it you need to make sure the texture is already loaded on the GPU, and to do that you need to basically create something on the display list that is using it. One way would be to include something in the atlas that you need on your main menu, then it will be ready loaded by the time the game starts. Alternatively if that isn't possible then just add a small nearly transparent image to the atlas and have a sprite use it somewhere in your menu, before it's needed in-game. That would have the same impact of loading the texture onto the GPU.

Link to comment
Share on other sites

Thank you for the fast reply!

Yes, It's running under the WebGL - I use the Phaser.AUTO in the canvas.
I've try that and it still pause the game.
I load it as a different sprite

this.tempChar = this.game.add.sprite(-200,-200,"mainCharacterFound");

:(

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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