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/mwg/rpg';
    import type { MovableSprite } from '@datamoc/mwg/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
    • Repositions by a delta instantly, with no tween and no walk animation - what a "jump" move-route step is, as opposed to moveBy's glide. Refuses while a moveBy is still in flight, the same as moveBy itself does, rather than fighting over x/y mid-tween.

      Parameters

      • dx: number
      • dy: number

      Returns boolean

    • 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