Jump to content

Animation does not play inside ticker loop?


Recommended Posts

I have been trying to wrap my head around getting an animation from a json spritesheet to play. (attached video of the result)

 

Firstly when i create the sprite, it only renders to the screen when it is in a loop.

Loop:

////Loop
m_canvas.ticker.add(delta => loop(delta));

///// Update loop function
function loop(delta){

    m_canvas.stage.removeChildren();

    m_map.Draw(loader, m_canvas,m_map.x,m_map.y);
    m_player.Draw(loader, m_canvas, m_player.x, m_player.y);
    
}

 

Now when i call the animated sprite.play() nothing happens. I tinkered the speed, no changes; It currently draws one of the frames.

Drawing and animating sprite in the player class:

    Draw(_loader, _canvas, _x, _y){
 
        _loader.load(setup);
       
        function setup(loader, resources) {
            const _textures = [];
            
            const _texture1 = PIXI.Texture.from('player_front_walk_0.png');
            _textures.push(_texture1);
            const _texture2 = PIXI.Texture.from('player_front_walk_1.png');
            _textures.push(_texture2);
            _textures.push(_texture1);
            const _texture3 = PIXI.Texture.from('player_front_idle_0.png');
            _textures.push(_texture3);
            
            const _ply = new PIXI.AnimatedSprite(_textures);

            _ply.position.set(_x, _y);

            _canvas.stage.addChild(_ply);
            _ply.loop = true;
            _ply.animationSpeed = .1;
            _ply.play();
        }
    }

I feel what is happening is that the animation is playing, but it doesnt show the frame change as the function is looping. So how can I get the animation to play? I even tried calling .play() outside of the loop and it did nothing.

Link to post
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...
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...