PokéRogue
    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
    • Parameters

      • camera: 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: 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'.

      • OptionalscaleFactor: number

        The scale factor to apply to the underlying mask texture. Can be used to balance memory usage and needed mask precision. This just adjusts the size of the texture; you must also adjust mask size to match, e.g. if scaleFactor is 0.5, your mask might be a Container with scale 0.5. It's easy to make things complicated when combining scale factor, object transform, and camera transform, so try to be precise when using this option. Default 1.

      Returns Mask

    active: boolean

    Toggle this boolean to enable or disable this filter, without removing it from and re-adding it to the Camera's filter list.

    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.

    camera: Camera

    A reference to the Camera that owns this filter.

    currentPadding: Rectangle

    The padding currently being used by this filter. This is read during rendering via getPadding, and may be updated by subclass implementations. 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: 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.

    scaleFactor: number

    The scale factor to apply to the underlying mask texture. A value less than 1 reduces the texture resolution to save memory at the cost of mask precision. A value greater than 1 increases resolution for sharper masking but uses more memory. When changing this value, you must also scale the mask GameObject or Container to match, so that its rendered output fills the texture correctly.

    viewCamera: Camera | null

    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.

    • Destroys this filter, releasing all references and resources.

      If a dynamic texture was created for a mask GameObject, it will also be destroyed.

      Returns void

    • Returns the raw padding required for this filter. This is typically not what you want to call; use getPaddingCeil instead. Values from this method are not rounded, which can cause quality loss.

      Override this method when creating a Filter that requires extra room, e.g. a blur or glow effect.undefined

      Returns Rectangle

      The padding required by this filter.

    • Returns the rounded padding required for this filter.

      Most filters don't need extra padding, but some may sample beyond the texture boundaries, such as a blur or glow effect.

      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.

      This method calls getPadding() to get the raw padding values, and uses Math.ceil() to set the values of paddingOverride and currentPadding.undefined

      Returns Rectangle

      The rounded padding required by this filter.

    • 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

      This filter instance.

    • Sets the GameObject used for the mask. The GameObject will be rendered to an internal DynamicTexture on the next render pass. Setting a new GameObject also sets needsUpdate to true, ensuring the texture is refreshed before the next frame is drawn.

      Parameters

      • gameObject: GameObject

        The GameObject to use for the mask.

      Returns this

      This Filter Controller.

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

      Parameters

      • Optionalleft: number | null

        The left 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 a static texture to use as the mask, looked up by key from the Texture Manager. Any previously assigned mask GameObject is cleared. Unlike a GameObject mask, a static texture mask does not update automatically between frames.

      Parameters

      • Optionaltexture: string

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

      Returns this

      This Filter Controller.

    • 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