question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to animate using AnimatedSprite

See original GitHub issue

Expected Behavior

Player walking animation as in:

https://user-images.githubusercontent.com/12777564/104153882-7fc52f00-5409-11eb-83fd-a76aa05a7845.mp4

Current Behavior

Player switching animations but not changing frames in:

https://user-images.githubusercontent.com/12777564/104153966-aaaf8300-5409-11eb-8e3f-d6ca85736b4e.mp4

Often, if I change the frame using gotoAndPlay(), the frame is set to this index in spite of emptying the cache while refreshing.

https://user-images.githubusercontent.com/12777564/104154122-1eea2680-540a-11eb-8df4-257ef5902bbe.mp4

Possible Solution

https://gitlab.com/Vivraan/mario50-pixijs/-/blob/227a18672242d9c468274e6a50c53cff1adda7f2/player.js#L63-73

        const move = (dt) => {
            if (this._vx != 0) {
                this._anim.textures = animations.walking
                if (!this._anim.playing) {
                    this._anim.play()
                }
                this._anim.scale.x = Math.sign(this._vx)
            } else {
                this._anim.textures = animations.idle
            }
        }

Steps to Reproduce

I raised this issue as a question rather than a bug report. The commit I’m working from is this one, which summarises the repro steps.

Environment

  • pixi.js version: ^5.3.7
  • Browser & Version: MS Edge 84.0.522.52 (Chromium)
  • OS & Version: Windows 10 20H2 19042.685
  • Running Example: Repo in GitLab

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
bigtimebuddycommented, Jan 11, 2021

@Vivraan I think your logic for move incorrectly calls every frame. This mean that it’s constantly setting textures on your animation frame after frame. If you cache the previous direction to only handle changes, it’s better.

Here’s an isolated example (click on the character on the right and then use the left and right arrow keys to see the animation switch). https://jsfiddle.net/bigtimebuddy/qo12kdnj/

This is not a limitation of the AnimatedSprite. In your case, this is an appropriate use.

Also, for questions (not bugs) please post to the Discussion section Q&A instead. Thanks!

1reaction
bigtimebuddycommented, Jan 18, 2021

I see your tagging. I unfortunately cannot help you debug your project at the moment, sorry. Hopefully someone else will be able to chime in. Good luck and keep at it, I’m sure you’ll figure it out.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to transition between AnimatedSprite animations
I want his animation to switch to "damaged" every time his hitbox overlaps with the player's sword, but it seems the animation won't...
Read more >
Godot 3.2 - Use AnimationPlayer with AnimatedSprite - YouTube
Your browser can't play this video. ... Godot 3.2 - Use AnimationPlayer with AnimatedSprite. 7.4K views 3 years ago. Duroxxigar. Duroxxigar.
Read more >
Support using AnimatedSprite and AnimationTree together #567
Simple 2D game with character animations. Describe the problem or limitation you are having in your project: I'm using AnimatedSprite for ...
Read more >
Animated Sprite helpful class - Playdate Developer Forum
I wrote sprite class extension that supports imagetables, animation, finite state machine and json config.
Read more >
Why doesn't my code use the correct animation?
AnimatedSprite is there to be used. And "I was told so" is not a good reason not to. Also, AnimatedSprite vs AnimationPlayer and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found