melonJS
    Preparing search index...

    Function followViewport

    • Have the viewport follow a level's area, as it does a Tiled map's: its bounds are the area's (or its own size where the area is smaller), and an area smaller than the viewport is centred in it, now and each time the viewport is resized. For the addTo of a format registered with level.registerFormat.

      A viewport follows one level at a time: following another replaces the first. Call the function returned from the level's destroy.

      Parameters

      • container: Container

        the container the level was added to

      • bounds: Bounds

        the level's area, in the container

      Returns Function

      call it to stop following

      // in a level's addTo(container, options)
      if (options.setViewportBounds !== false) {
      const area = new Bounds();
      area.setMinMax(0, 0, this.width, this.height);
      this.unfollow = level.followViewport(container, area);
      }
      // and in its destroy()
      this.unfollow?.();