mwg API
    Preparing search index...

    Class GridMover

    Grid movement tweened between tiles, with a walk cycle - what turns "the player pressed right" into a sprite that glides from one tile to the next and faces the way it is going, rather than teleporting square to square.

    This owns position and animation only. Whether the target tile is passable, whether something is standing on it, whether stepping onto it should trigger an event - all of that is a question for the map, asked before moveBy is called.

    import { GridMover } from '@datamoc/mw_games/rpg';
    import type { MovableSprite } from '@datamoc/mw_games/rpg';

    declare const heroSprite: MovableSprite;

    const mover = new GridMover(heroSprite, 5, 5, { tileWidth: 32, tileHeight: 32, speed: 4 });
    mover.moveBy(1, 0); // a tile check already confirmed this is passable

    // in the game loop:
    mover.update(1 / 60);
    Index
    facing: Direction4 = 'down'
    x: number
    y: number
    • starts moving one tile in the given direction; false when already moving

      Parameters

      • dx: number
      • dy: number

      Returns boolean

    • Faces a direction without moving - what a bump into a wall or an NPC turns into, rather than nothing at all. Without this, a player who arrives beside an NPC from the "wrong" side can never turn to face it, since an actual step that way is blocked and moveBy only ever faces the direction it successfully moves in.

      Parameters

      • dx: number
      • dy: number

      Returns void