dittofittoe Posted July 17, 2021 Share Posted July 17, 2021 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. 905771104_2021-07-1723-24-47.mp4 Quote Link to comment Share on other sites More sharing options...
dittofittoe Posted July 19, 2021 Author Share Posted July 19, 2021 Solved: Dont play an animation inside of a loop unless you create a run once function. I rewrote the script and drew the sprite to the canvas OUTSIDE of the loop. I was able to manipulate the values inside the ticker loop and it still updated (JS defies all knowledge I have of procedural programming). Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.