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.

Animated Sprite Current Time Infinity on Tab Change

See original GitHub issue

Hey guys, I found an issue with Animated Sprites / Movie Clip. When I change tabs with an animation running, the whole game breaks.

When you have a running animation, the current frame is calculated with this:

AnimatesSprite.js 372: var currentFrame = Math.floor(this._currentTime) % this._textures.length;

However, when you change tab, this._currentTime is being set to Infinity, and so this._currentFrame is being set to NaN. This in turn causes this._textures[this._currentFrame] to return undefined and then the renderer crashes because an invalid texture has been set on the sprite.

I did a quick isFinite stop this from breaking the renderer.

` get: function get() {

    if(!isFinite(this._currentTime)) {
        this._currentTime = 0;
    }

    var currentFrame = Math.floor(this._currentTime) % this._textures.length;       

    if (currentFrame < 0) {
        currentFrame += this._textures.length;
    }

    return currentFrame;

} `

Hope this might help someone else too!

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
megmutcommented, May 29, 2017

Sorry I completely forgot… let me try and get one done tonight 😃

0reactions
lock[bot]commented, Feb 24, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Animated Sprite Current Time Infinity on Tab Change #3709
Hey guys, I found an issue with Animated Sprites / Movie Clip. When I change tabs with an animation running, the whole game...
Read more >
Animation
The animation property in CSS can be used to animate many other CSS properties such as color, background-color, height, or width.
Read more >
Sprites not loading on canvas
I'm trying to create a game with sprite animation, but I can't seem to load both the animated sprite and the canvas at...
Read more >
2D ANIMATION RIGGING IN UNITY | PNG & PSB FILES
In this Unity tutorial we will create a Sprite animation in Unity! We will be animating using Unity's bone rigging, and I will...
Read more >
Animated Sprite & Sprite Frame | Godot Basics Tutorial | Ep 60
Welcome to the Godot Basics Tutorial Series, in this episode I take a quick and brief look at the Animated Sprite and Sprite...
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