mwg API
    Preparing search index...

    Function isOnScreen

    • Whether a world-space point is on screen, for skipping animation work nobody sees.

      The edges count as on screen, and margin grows the box by that many world units on every side, for sprites whose bodies spill past their anchor point. Under a rotated camera the checked box is the axis-aligned one around the turned viewport (the same over-inclusive box TileMap.cull uses), so this can only ever animate too much, never freeze something the player can see.

      Parameters

      • camera: Camera
      • x: number
      • y: number
      • margin: number = 0

      Returns boolean

      import { Camera, isOnScreen } from '@datamoc/mwg/two-d/render';

      declare const camera: Camera;

      if (isOnScreen(camera, 160, 160)) console.log('the market square, animate it');
      console.log(isOnScreen(camera, 10000, 10000, 32)); // far away, even with a margin