Jump to content

KaboomJS Sprite Animations


pdiddles03
 Share

Recommended Posts

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);
            })
Link to comment
Share on other sites

  • 2 months later...

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 :)

Link to comment
Share on other sites

  • 4 weeks later...

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);
});

 

Link to comment
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...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...