0

I want to flip my character to move left so that I dont have to animate a new left animation on every character (Yeah Im lazy). Is there an easy way to do this?

-Using kaboom.js

onKeyDown("a", () => { 
  player.move(-SPEED, 0), //moves sprite
  onKeyPress("a", () => { 
    player.play("RunSide"), //plays animation
    player.scale = -1, //trying to flip it here :)
    onKeyRelease("a", () => { 
      player.stop(), //stops animation
      player.frame = 0 
    }) 
  }) 
})
Ash Hanson
  • 23
  • 3

2 Answers2

0

player.flipX(true) should work assuming that player is the sprite that you created

Fybir_
  • 16
0

The demos on the Kaboom website has an example https://kaboomjs.com/play?demo=sprite

onKeyDown("left", () => {
    player.move(-SPEED, 0)
    player.flipX(true)
    if (player.isGrounded() && player.curAnim() !== "run") {
        player.play("run")
    }
})

onKeyDown("right", () => {
    player.move(SPEED, 0)
    player.flipX(false)
    if (player.isGrounded() && player.curAnim() !== "run") {
        player.play("run")
    }
})

I think the .flipX() method is toggled on/off, so here it needs toggled off when the opposite direction is pressed.

By the way Kaboom has a Discord for help