Aller au contenu

Bloc évanescent

Fanny

Les blocs évanescents n’aparaissent que lorsqu’un personnage s’en rapproche.

  1. load.js
    const PNG = [
    "invisible",
    "grass",
    ]
  2. config.js
    const TILE_CONFIG = {
    "*": () => [ // text
    sprite("invisible"),
    area(),
    body({ isStatic: true }),
    anchor("bot"),
    offscreen({ hide: true }),
    vanishing(),
    opacity(),
    ],
    "#": () => [ // player 1
    sprite("bean"),
    platformerController(),
    jumpController(),
    sleep(),
    alive(),
    opacity(),
    scale(),
    health(1, 4),
    area(),
    body(),
    respawn(),
    falling(),
    rotate(),
    pos(0, -20),
    anchor("center"),
    ],
    "=": () => [ // block
    sprite("grass"),
    area({ collisionIgnore: ["agent"] }),
    body({ isStatic: true }),
    anchor("bot"),
    offscreen({ hide: true }),
    tile({ isObstacle: true }),
    ],
    }
  3. level.js
    const LEVELS = [
    {
    map: `
    *
    **
    ***
    **
    ***
    #
    *****
    `,
    },
    ]
vanishing()
example
config.js
vanishing({
invisibleDistance: 240,
visibleDistance: 60,
tag: "alive"
}),