Jump to content

TIL: You can animate sprites from the atlas


Recommended Posts

I always thought you had to load in another spritesheet specifying the specific sizes and frames like this:

game.load.spritesheet('myguy', 'assets/myguy.png', 50, 30, 5);

But, if you actually already have a sprite atlas loaded, you can set an animation to that atlas sprite like this:


PlayerSprite  =  game.add.sprite(player_start_x, player_start_y, 'GameSprite', 'Player1');PlayerSprite.animations.add('idle', ['Player0', 'Player1'], 10, true);PlayerSprite.animations.play('idle');
{	"frames": {		"Player0": {			"frame": {				"x": 4,				"y": 470,				"w": 54,				"h": 135			}		},					"Player1": {			"frame": {				"x": 4,				"y": 335,				"w": 54,				"h": 135			}		},}}

I don't know about the performance if you're using a LARGE sprite, but I think it's minuscule. I'm using a 1500x1300 sprite right now that is over 500kb in size and animating characters and oh boy it seems fine. I will be using seperate image files for skills though as I do believe loading in a huge, huge image would cause issues but I havn't had any yet with just a couple basic animations.


  The whole reason I find this useful is because it saves you an extra HTTP request, while still being able to use your atlas sprites!! Go Phaser  :wub:

Link to comment
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.
  • Create New...