Aller au contenu

Orientation de la sprite

L’image représentant ton personnage a peut-être une direction. Ce hack te permetttra d’afficher ton personnage dans la diretion vers la quelle il se déplace.

  1. component.js
    function spriteFacing(p) {
    const param = {
    reversed: false,
    ...p
    }
    return {
    update() {
    this.flipX = (this.facing > 0) ? (param.reversed) : !(param.reversed)
    },
    }
    }
  2. config.js
    "#": () => [ // player 1
    spriteFacing(),
    sprite("bean"),
    platformerController(),
    alive(),
    opacity(),
    scale(),
    health(1, 4),
    area(),
    anchor("bot"),
    body(),
    respawn(),
    falling(),
    ],
example
config.js
spriteFacing({
reversed: false
}),