Sprite sheet animation vs loadTexture

Recommended Posts

Hello everybody.
I am trying to optimize my game, and would like to know, which of this two Phaser techniques would be  more optimal in term of resource usage.

On one side I got SpriteSheet -  'atlasJSONHash'.

// preload

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

// create

var foo = game.add.sprite(0, 0, 'image');
    foo.animation.play('main', 30, true);

On other side I got just a sprite with a texture, and I'm changing  it's texture in the Phaser render function, with another preloaded texture.

// preload

var textureArray = [];
    textureArray.push(game.load.image('image0', 'assets/image0.png') );
    textureArray.push(game.load.image('image1', 'assets/image1.png') );
    textureArray.push(game.load.image('image2', 'assets/image2.png') );
    // and so on, 'in the game this is done by a loop'.

// create

var i = 0;
var foo = game.add.sprite(0, 0, 'image0');

// render

foo.loadTexture('image' + i);

In both cases there are same images [img0, img1, img2, ...], but in first example they are combined into a spritesheet, and in other they are separately loaded as a png images.


I would like to know, which would you recommend, again in terms of resource consumption.

Thank you in advance.

Share this post

Link to post
Share on other sites
On 3/29/2017 at 7:11 PM, scheffgames said:

As far as I know the spritesheet approach it's the best in terms of performance since the GPU has to deal with only one image instead of lots of little ones. 

Thank you for respond.

Share this post

Link to post
Share on other sites

I had "similar" question recently and yes using spritesheets is best of course (as you probably know all games of any kind use that) but then there is a question spriteSheet vs spriteAtlas 

I asked here http://www.html5gamedevs.com/topic/9588-texture-atlas-better-than-spritesheets-performancewise/ and there is one good source of info.. after some concepts I managed to get just two calls to graphic card (even when using more than 1 spriteAtlas with many images inside of them) and game is much faster in terms of what GPU has to deal with

read more here https://phaser.io/tutorials/advanced-rendering-tutorial/part2


Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.