phaser - v4.0.0-rc.4
    Preparing search index...

    The Mask Filter Controller.

    This filter controller manages a mask effect.

    A mask uses a texture to hide parts of an input. It multiplies the color and alpha of the input by the alpha of the mask in the corresponding texel.

    Masks can be inverted, which switches what they hide and what they show.

    Masks can use either a texture or a GameObject. If a GameObject is used, the mask will render the GameObject to a DynamicTexture and use that. The mask will automatically update when the GameObject changes, unless the autoUpdate flag is set to false.

    When the mask filter is used as an internal filter, the mask will match the object/view being filtered. This is useful for creating effects that follow the object, such as effects intended to match an animated sprite.

    When the mask filter is used as an external filter, the mask will match the context of the camera. This is useful for creating effects that cover the entire view.

    An optional viewCamera can be specified when creating the mask. If not used, mask objects will be viewed through the current camera, or through a default camera if no other option is set. For example, when rendering to a DynamicTexture outside the normal rendering flow.

    A Mask effect is added to a Camera via the FilterList component:

    const camera = this.cameras.main;
    const texture = 'MyMask';

    camera.filters.internal.addMask(texture);
    camera.filters.external.addMask(texture, true, myCamera);

    Hierarchy (View Summary)

    Index

    Constructors

    • Parameters

      • camera: Cameras.Scene2D.Camera

        The Camera that owns this filter.

      • Optionalmask: string | GameObject

        The source of the mask. This can be a unique string-based key of the texture to use for the mask, which must exist in the Texture Manager. Or it can be a GameObject, in which case the mask will render the GameObject to a DynamicTexture and use that. Default '__WHITE'.

      • Optionalinvert: boolean

        Whether to invert the mask. Default false.

      • OptionalviewCamera: Cameras.Scene2D.Camera

        The Camera to use when rendering the mask with a GameObject. If not specified, uses the scene's main camera.

      • OptionalviewTransform: "local" | "world"

        The transform to use when rendering the mask with a GameObject. 'local' uses the GameObject's own properties. 'world' uses the GameObject's parentContainer value to compute a world position. Default 'world'.

      Returns Filters.Mask

    Properties

    active: boolean

    Toggle this boolean to enable or disable this filter, without removing and adding it from the Game Object.

    allowBaseDraw: boolean

    If true, this filter will be permitted to draw to the base texture. This can be unwanted if, for example, the filter doesn't actually draw anything.

    This is an internal flag used by the renderer. You should not modify this value directly.

    autoUpdate: boolean

    Whether the mask should automatically update. This only applies when the mask is a GameObject. If false, the mask will not change even if the GameObject changes.

    A reference to the Camera that owns this filter.

    currentPadding: Geom.Rectangle

    The padding currently being used by this filter. This is set and used during rendering using getPadding. It is necessary for filters being used in an external list. You should not modify this value directly.

    The underlying texture used for the mask.

    ignoreDestroy: boolean

    Whether this filter controller will be destroyed when the FilterList that owns it is destroyed. If you enable this, you must ensure that you clean up the filter controller at an appropriate time. This allows you to reuse a controller for multiple objects; this is not recommended unless you know what you're doing. It tends to work best with external filters.

    invert: boolean

    Whether to invert the mask. An inverted mask switches what it hides and what it shows.

    maskGameObject: GameObject

    The GameObject used for the mask. This is only set if the mask is a GameObject.

    needsUpdate: boolean

    Whether the mask needs updating, once. This only applies when the mask is a GameObject. If true, the mask will be updated before the next render. This is automatically set to true when the mask is a GameObject, but it turns off after the mask is updated.

    paddingOverride: Geom.Rectangle

    Padding override. This is on by default. If this is set, the filter will use this padding instead of calculating it. Prefer using setPaddingOverride instead of modifying this directly.

    renderNode: string

    The ID of the RenderNode that this filter uses.

    viewCamera: Cameras.Scene2D.Camera

    The Camera to use when rendering the mask. If not specified, uses the currently rendering camera, or failing that, an internal Camera.

    viewTransform: "local" | "world"

    The transform type to use when rendering the mask with a GameObject. 'local' uses the GameObject's own properties. 'world' uses the GameObject's parentContainer value to compute a world position. This only applies when the mask is a GameObject.

    Methods

    • Returns the padding required for this filter, and sets currentPadding to the result. Most filters don't need extra padding, but some might sample beyond the texture size, such as a blur.

      The bounds are encoded as a Rectangle. To enlarge the bounds, the top and left values should be negative, and the bottom and right values should be positive.

      Returns Geom.Rectangle

    • Sets the active state of this filter.

      A disabled filter will not be used.

      Parameters

      • value: boolean

        true to enable this filter, or false to disable it.

      Returns this

    • Sets the padding override. If this is set, the filter will use this padding instead of calculating them. it Call setPaddingOverride(null) to clear the override. Call setPaddingOverride() to set the padding to 0.

      Parameters

      • Optionalleft: number

        The top padding. Default 0.

      • Optionaltop: number

        The top padding. Default 0.

      • Optionalright: number

        The right padding. Default 0.

      • Optionalbottom: number

        The bottom padding. Default 0.

      Returns void

    • Sets the texture used for the mask.

      Parameters

      • Optionaltexture: string

        The unique string-based key of the texture to use for displacement, which must exist in the Texture Manager. Default '__WHITE'.

      Returns this

    • Updates the DynamicTexture for the mask. The DynamicTexture is created or resized if necessary. This is called automatically during rendering when the mask is a GameObject and the needsUpdate or autoUpdate flags are set. It should not be called directly.

      Parameters

      • width: number

        The width of the DynamicTexture.

      • height: number

        The height of the DynamicTexture

      Returns void