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

    The Threshold Filter Controller.

    This controller manages a threshold filter. Input values are compared to a threshold value or range. Values below the threshold are set to 0, and values above the threshold are set to 1. Values within the range are linearly interpolated between 0 and 1.

    This is useful for creating effects such as sharp edges from gradients, or for creating binary effects.

    The threshold is stored as a range, with two edges. Each edge has a value for each channel, between 0 and 1. If the two edges are the same, the threshold has no interpolation, and will output either 0 or 1. Each channel can also be inverted.

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

    const camera = this.cameras.main;

    camera.filters.internal.addThreshold();
    camera.filters.external.addThreshold();

    Hierarchy (View Summary)

    Index

    Constructors

    • Parameters

      • camera: Cameras.Scene2D.Camera

        The Camera that owns this filter.

      • Optionaledge1: number | number[]

        The first edge of the threshold. This may be an array of the RGBA channels, or a single number to apply to all 4 channels. Default 0.5.

      • Optionaledge2: number | number[]

        The second edge of the threshold. This may be an array of the RGBA channels, or a single number to apply to all 4 channels. Default 0.5.

      • Optionalinvert: boolean | boolean[]

        Whether each channel is inverted. This may be an array of the RGBA channels, or a single boolean to apply to all 4 channels. Default false.

      Returns Threshold

    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.

    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.

    edge1: number[]

    The first edge of the threshold. This contains the lowest value for each channel.

    edge2: number[]

    The second edge of the threshold. This contains the highest value for each channel. If it is the same as the first edge, the threshold is a single value.

    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 each channel is inverted.

    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.

    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

    • Set the edges of the threshold. If the second edge is not provided, it will be set to the first edge.

      This ensures that the first edge is not greater than the second edge. It may swap channels between edges to ensure this.

      Parameters

      • Optionaledge1: number | number[]

        The first edge of the threshold. This may be an array of the RGBA channels, or a single number to apply to all 4 channels. Default 0.5.

      • Optionaledge2: number | number[]

        The second edge of the threshold. This may be an array of the RGBA channels, or a single number to apply to all 4 channels. Default 0.5.

      Returns Threshold

    • Set the invert state of the threshold. If invert is not provided, it will be set to false.

      Parameters

      • Optionalinvert: boolean | boolean[]

        Whether each channel is inverted. This may be an array of the RGBA channels, or a single boolean to apply to all 4 channels. Default false.

      Returns Threshold

    • 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