Jump to content

TIL: You can animate sprites from the atlas


WombatTurkey
 Share

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

 Share

  • Recently Browsing   0 members

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