Jump to content

How expensive is loadTexture?


Jackal16
 Share

Recommended Posts

The Phaser manual states that sprite.loadTexture is an expensive operation, is this still true if the texture has been loaded to the game cache in preload?

 

Example:

 

function preload() {

game.load.image('image1', 'assets/image1.png');

game.load.image('image2', 'assets/image2.png');

}

 

 

function construct() {

mySprite = game.add.sprite(xpos, ypos, 'image1');

}

 

Somewhere later in the game loop we change to image 2

 

mySprite.loadTexture('image2');​

 

 

Thanks

 

Link to comment
Share on other sites

It's still true, but it's not to do with the Phaser Cache - it's to do with the GPU. If the texture is already loaded on the GPU (i.e. in use by another sprite) then loadTexture is fine. If the texture needs to be pushed up to the GPU then yes it can take a small performance hit doing that. It's very small, but if you do it often then the issues can mount up.

Link to comment
Share on other sites

It's still true, but it's not to do with the Phaser Cache - it's to do with the GPU. If the texture is already loaded on the GPU (i.e. in use by another sprite) then loadTexture is fine. If the texture needs to be pushed up to the GPU then yes it can take a small performance hit doing that. It's very small, but if you do it often then the issues can mount up.

What about CANVAS renderer?

Link to comment
Share on other sites

@ Rich - my game seems to run fine in the browser most of the time but every so often there seems to be a short laggy period. Due to the fact I allocate all objects at startup I don't think its the GC - any ideas off the top of you head?

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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