odelia Posted January 12, 2016 Share Posted January 12, 2016 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 More sharing options...
rich Posted January 12, 2016 Share Posted January 12, 2016 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 More sharing options...
odelia Posted January 12, 2016 Author Share Posted January 12, 2016 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 More sharing options...
odelia Posted January 12, 2016 Author Share Posted January 12, 2016 OK, I just replaced the new sprite with the old one. Not the best solution, but it worked.... Thank you. Link to comment Share on other sites More sharing options...
Recommended Posts