pdiddles03 Posted December 14, 2021 Share Posted December 14, 2021 I'm playing around with KaboomJS and I've been trying to animate a spritesheet. Every tutorial I Have seen says all you ahve to do is listen for left, right up or down keypress and animate it like below. My animation will only play once though. Any thoughts on how to get this animation to repeat? loadSprite('player', 'spritesheets/player.png', { sliceX:6, // sliceY:18, height:18, width:63, anims:{ idle:{from:5,to:5}, walk:{from:0,to:1} } }) keyPress('right', ()=>{ player.play('walk'); player.flipX(0); }) Quote Link to comment Share on other sites More sharing options...
foundthiswhilegoogling Posted February 21, 2022 Share Posted February 21, 2022 This is a late reply but try to change onKeyPress to onKeyDown and it should continue to cycle through the animation aslong as you're pressing the button. Maybe you want to just cycle the animation infinitly by pressing once thenyou can add "loop": true, Don't know if this helps you at all but I hope you find a solution to your problem Quote Link to comment Share on other sites More sharing options...
Dugster Posted March 17, 2022 Share Posted March 17, 2022 I am having similar issues. So far, I've got the player to move by calling setInterval on keyPress and then clearing it on keyRelease... I'm playing around with the values to make it look smooth... but if anyone knows of a better way that would be great? let myInterval function animateR(){ myInterval = setInterval(() => { player.play("run"); player.move(1000, 0); }, 100); } function animateL(){ myInterval = setInterval(() => { player.play("run"); player.move(-1000, 0); }, 100); } keyPress("right", () => { player.scale.x = 1; animateR(); }); keyPress("left", () => { player.scale.x = -1; animateL(); }); keyRelease("left", () => { clearInterval(myInterval) }); keyRelease("right", () => { clearInterval(myInterval); }); 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.