我想翻转我的角色向左移动,这样我就不必在每个角色上动画一个新的左动画(是的,我很懒)。有简单的方法吗?
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
})
})
})
player. flipx (true)应该可以工作,假设player是你创建的精灵
在Kaboom网站上的演示有一个例子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")
}
})
我认为.flipX()
方法是打开/关闭的,所以在这里,当相反的方向被按压时,它需要关闭。
顺便说一下,Kaboom有一个Discord for help