Jump to content

Definition animations with sprite names.


Recommended Posts

Hey Team,

Quick question here: So we can define animations using the two ways below (Copy/pasted from Panda examples page). 

Is it possible to define an animation like the 3rd way I listed below? I tried to get it to work.. it didn't, so I assume it's not supported. But seems more convenient to build up an animation this way?

The first method (defining indexes) is not very convenient. I'm pretty sure with TexturePacker, my texture sheet is going to be jumbled up, and indexes will change as I continue to add more sprites.

The second way is better, but I can't define 'run', or 'jump'-style animations, which I'd like to.

Any thoughts? Am I missing something here?

//One way
this.anim = new game.Animation('player.atlas');
        this.anim.addAnim('run', [3, 4, 5, 6, 7, 8, 9, 10]);
        this.anim.addAnim('jump', [2, 1], { speed: 3, loop: false });

//second way
var anim = new game.Animation([

//third way.. won't work??
this.anim = new game.Animation('player.atlas');
        this.anim.addAnim('run', [


Link to comment
Share on other sites

There is actually three different ways to use addAnim function.

1. Use frame indexes

addAnim('run', [3, 4, 5, 6, 7]);

2. Define start frame index and number of frames

addAnim('run', 3, 5); // Animation starts from frame index 3 and contains 5 frames

3. Use frames that start with specific name

addAnim('run', 'anim_run'); // Uses all frames that start with name anim_run

Third is handy if you name your frames properly, like


This way if you add more frames to your anim, they will be automatically used.

Link to comment
Share on other sites

Ah ha, yep, that 3rd one would be handy!

But I won't necessarily have my animations named in a simple sequence like that. Sometimes we want animation to reuse a specific image.

Take a typical retro-style game. A walking cycle might have 4 frames like this:


But this is actually only 3 separate images. A standing image, a right-foot forward image, and a left-foot forward image. By mixing 0,1,3,0, we don't need to load the second standing image.

So still not ideal.

Link to comment
Share on other sites

Ah i see.

I have added now support for frame names, instead of frame indexes in the array, you can now use frame names (or even mix indexes and names in same array):

.body(function() {


game.createScene('Main', {
    init: function() {
        var player = new game.Animation('player.atlas');
        player.addAnim('run', ['run-01.png', 'run-02.png']);


Just update to latest develop version.

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...