Jackal16 Posted August 15, 2015 Share Posted August 15, 2015 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 More sharing options...
rich Posted August 17, 2015 Share Posted August 17, 2015 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 More sharing options...
tips4design Posted August 17, 2015 Share Posted August 17, 2015 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 More sharing options...
Jackal16 Posted August 18, 2015 Author Share Posted August 18, 2015 OK thanks for the reply, so if the texture have already been used by another sprite at least once it should be ok? Is there an alternative to loadTexture that is more efficient? Link to comment Share on other sites More sharing options...
rich Posted August 18, 2015 Share Posted August 18, 2015 Canvas is fine, it won't make any real difference. There's no alternative to loadTexture, no - if the texture isn't on the GPU it needs uploading, it's as simple as that. There's no avoiding it. tips4design 1 Link to comment Share on other sites More sharing options...
Jackal16 Posted August 18, 2015 Author Share Posted August 18, 2015 @ 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 More sharing options...
Recommended Posts