Jump to content

Correct way to play multiple animations


wijesijp
 Share

Recommended Posts

I wanted to play multiple animations with a AnimatedSprite.

I setup the animated sprite in following manner.

    this.spriteSheet = this.loader.resources["images/atlus_runner.json"].spritesheet
    this.anim = new PIXI.extras.AnimatedSprite(
      this.spriteSheet.animations["walk"]
    );
    this.anim.animationSpeed = 0.2;
    this.anim.loop = true;
    this.anim.play();
    this.addChild(this.anim);

When I wanted to play another animation, I did it in following manner

    var newAnim = this.spriteSheet.animations["jump"];
    this.anim.stop();
    this.anim.textures = newAnim;
    this.anim.play();

I stop the current animation, set the new textures and play animation again.

Is this the correct way of playing another animation?

 

Link to comment
Share on other sites

There's no "correct" way of playing stuff with AnimatedSprite because everyone uses their own animators based on it. I remember that AnimatedSprite was patched maaaaany times and that class is never enough. People also use different animation loops (not pixi-ticker based).

If you go to "make my own animator" route, please look at https://github.com/gameofbombs/pixi-heaven/blob/master/src/animation/AnimationState.ts , usage example: https://github.com/gameofbombs/pixi-heaven#animation . Its good approach "animator-as-component" made by genius @finscn

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.

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

Loading...
 Share

  • Recently Browsing   0 members

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