melonJS
    Preparing search index...

    Class MaskEffect

    A camera effect that performs a mask-based scene transition.

    A shape closes on a point to hide the scene, filling the screen around it with a solid color, and opens from it again to reveal the scene. The shape can be:

    • an Ellipse (an iris, the default) or a Polygon, unit-sized and centred on its origin;
    • an image, or the name of a preloaded one: the shape is its silhouette, its transparent pixels outside and the others inside (colors do not matter, and gaps inside the outline are filled);
    • a Sprite: the silhouette of the frame it shows when the effect starts, facing the way it faces (not its scale or rotation: the shape is grown to the screen's size anyway).

    The shape grows and shrinks about its thickest part (the origin of a unit Polygon or Ellipse), and that point sits on the centre of the screen, or on center: a renderable, at the place it is drawn when the effect starts, such as the player. With invert, the shape is the cover instead of the window: filled with the color, it grows out of that point until it covers the screen, and shrinks away to reveal it.

    Whatever the shape and the point, the shape is grown until it holds the whole screen, so a reveal ends with the scene fully uncovered. It is drawn with plain images and fills, the same on every renderer. A shape that cannot be used (an unknown image name, an image that cannot be read, an empty one, a destroyed sprite) warns once and is an iris instead.

    // iris transition (circle shrinks to hide the scene)
    camera.addCameraEffect(new MaskEffect(camera, {
    shape: new Ellipse(0, 0, 1, 1),
    color: "#000",
    duration: 500,
    direction: "hide",
    }));
    // diamond reveal transition
    camera.addCameraEffect(new MaskEffect(camera, {
    shape: new Polygon(0, 0, [
    { x: 0, y: -1 }, { x: 1, y: 0 },
    { x: 0, y: 1 }, { x: -1, y: 0 },
    ]),
    color: "#000",
    duration: 500,
    direction: "reveal",
    }));
    // a star wipe from a preloaded silhouette image
    camera.addCameraEffect(new MaskEffect(camera, {
    shape: "star_mask", // or loader.getImage("star_mask")
    color: "#000",
    duration: 500,
    }));
    // the player's own silhouette closing on the player
    camera.addCameraEffect(new MaskEffect(camera, {
    shape: player,
    center: player,
    color: "#000",
    duration: 500,
    }));
    // a black heart growing out of the player until it covers the screen
    camera.addCameraEffect(new MaskEffect(camera, {
    shape: "heart_mask",
    center: player,
    invert: true,
    color: "#000",
    duration: 400,
    }));

    Hierarchy (View Summary)

    Index
    • Parameters

      • camera: Camera2d

        the camera to apply the transition to

      • options: MaskEffectOptions

        transition parameters, see MaskEffectOptions

        The settings of a MaskEffect, as its constructor takes them.

        • Optionalcenter?: MaskCenter

          where the shape closes and opens: a renderable (where it is drawn when the effect starts) or a point in the camera's screen coordinates. The centre of the screen by default

        • color: string | Color

          CSS color value or Color instance for the transition fill

        • Optionaldirection?: "hide" | "reveal"

          "hide" covers the scene (the default), "reveal" uncovers it

        • Optionalduration?: number

          transition duration in milliseconds (500 by default)

        • Optionalinvert?: boolean

          make the shape the cover rather than the window: it grows out of center to hide the scene

        • OptionalonComplete?: () => void

          callback when the transition finishes

        • Optionalshape?: MaskShape

          an Ellipse or Polygon (unit-sized), an image or the name of a preloaded one, or a Sprite; an iris when omitted

      Returns MaskEffect

    camera: Camera2d

    the camera this effect is attached to

    center: { x: number; y: number } | undefined

    the point the shape closes on and opens from, in the camera's screen coordinates, read when the effect started; undefined for the centre of the screen

    color: Color

    the transition fill color

    direction: "hide" | "reveal"

    transition direction

    duration: number

    the transition duration, in milliseconds

    invert: boolean

    true when the shape is the cover rather than the window: it grows to hide the scene and shrinks to reveal it

    false
    
    isComplete: boolean

    whether this effect has finished and should be removed

    isPersistent: boolean

    whether this effect should persist across camera/game resets (e.g. transition effects that span state changes)

    false
    
    onComplete: (() => void) | undefined

    optional callback when transition completes

    progress: { value: number }

    current progress value (0 = fully covered, 1 = fully visible)

    shape: MaskShape | undefined

    the shape as given: an Ellipse or Polygon template, an image, the name of one, or a sprite; undefined for the default iris

    tween: Tween

    the tween controlling progress