PokéRogue
    Preparing search index...

    The Key filter controller.

    The Key effect removes or isolates a specific color from an image. It can be used to remove a background color from an image, or to isolate a specific color for further processing.

    By default, Key will remove pixels that match the key color. You can instead keep only the matching pixels by setting isolate.

    The threshold and feather settings control how closely the key color matches. A match is measured by "distance between color vectors"; that is, how close the RGB values of the pixel are to the RGB values of the key color.

    A Key filter is added to a Camera via the FilterList component:

    const camera = this.cameras.main;
    camera.filters.internal.addKey({ color: '#ff00ff' });
    camera.filters.external.addKey({ color: 0x00ff00 });

    Hierarchy (View Summary)

    Index
    • Parameters

      • camera: Camera

        The camera that owns this filter.

      • Optionalconfig: KeyConfig

        The configuration for the filter. Default {}.

      Returns Key

    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.

    camera: Camera

    A reference to the Camera that owns this filter.

    color: number[]

    The color to use for the key. It is an array of 4 numbers between 0 and 1, representing the RGBA values.

    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.

    feather: number

    The feathering amount for the key color. Pixels outside the threshold, but still within the feather, will be a partial match. This should be a value between 0 and 1.

    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.

    isolate: boolean

    Whether to keep the region matching the key color. If true, the region matching the key color will be kept, and the rest will be removed. If false, the region matching the key color will be removed, and the rest will be kept.

    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.

    threshold: number

    The threshold for the key color. A pixel is considered to be the key color if the difference between the pixel and the key color is less than the threshold. This should be between 0 and 1. The default threshold is 1 / 16, which is a good starting point for most images.

    • Destroys this Controller and nulls any references it holds.

      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 alpha value to use for the key. Alpha controls the opacity of pixels matched by the key color, in the range 0 to 1. This is stored in the fourth element of the color array. The RGB color values are preserved.

      Parameters

      • alpha: number

        The alpha value to set on the key texture, between 0 (fully transparent) and 1 (fully opaque).

      Returns this

      This Filter Controller.

    • Sets the color to use for the key. This is stored in the first three elements of the color array. The alpha value is preserved.

      Parameters

      • color: string | number | number[] | Color

        The color to use for the key. It can be a hexcode number or string, an array of 3 numbers between 0 and 1, or a Color object.

      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