jetlag2d
    Preparing search index...

    Class ColorReplaceFilter

    ColorReplaceFilter, originally by mishaa, updated by timetocode http://www.html5gamedevs.com/topic/10640-outline-a-sprite-change-certain-colors/?p=69966
    originalfilter

    // replaces true red with true blue
    someSprite.filters = [new ColorReplaceFilter({
    originalColor: [1, 0, 0],
    targetColor: [0, 0, 1],
    tolerance: 0.001
    })];
    // replaces the RGB color 220, 220, 220 with the RGB color 225, 200, 215
    someOtherSprite.filters = [new ColorReplaceFilter({
    originalColor: [220/255.0, 220/255.0, 220/255.0],
    targetColor: [225/255.0, 200/255.0, 215/255.0],
    tolerance: 0.001
    })];
    // replaces the RGB color 220, 220, 220 with the RGB color 225, 200, 215
    someOtherSprite.filters = [new ColorReplaceFilter({ originalColor: 0xdcdcdc, targetColor: 0xe1c8d7, tolerance: 0.001 })];

    Hierarchy

    Index
    • Parameters

      • Optionaloptions: ColorReplaceFilterOptions

        Options for the ColorReplaceFilter constructor.

      Returns ColorReplaceFilter

    • Parameters

      • OptionaloriginalColor: number

        The color that will be changed, as a 3 component RGB e.g. [1.0, 1.0, 1.0]

      • OptionalnewColor: number

        The resulting color, as a 3 component RGB e.g. [1.0, 0.5, 1.0]

      • Optionalepsilon: number

        Tolerance/sensitivity of the floating-point comparison between colors (lower = more exact, higher = more inclusive)

      Returns ColorReplaceFilter

      since 6.0.0

    antialias: FilterAntialias

    should the filter use antialiasing?

    inherit
    
    blendRequired: boolean

    Whether or not this filter requires the previous render texture for blending.

    false
    
    clipToViewport: boolean

    Clip texture into viewport or not

    true
    
    compatibleRenderers: number

    A number that uses two bits on whether the shader is compatible with the WebGL renderer and/or the WebGPU renderer. 0b00 - not compatible with either 0b01 - compatible with WebGL 0b10 - compatible with WebGPU This is automatically set based on if a GlProgram or GpuProgram is provided.

    enabled: boolean

    If enabled is true the filter is applied, if false it will not.

    glProgram: GlProgram

    An instance of the GL program used by the WebGL renderer

    gpuProgram: GpuProgram

    An instance of the GPU program used by the WebGPU renderer

    groups: Record<number, BindGroup>
    padding: number

    The padding of the filter. Some filters require extra space to breath such as a blur. Increasing this will add extra width and height to the bounds of the object that the filter is applied to.

    0
    
    resolution: number | "inherit"

    The resolution of the filter. Setting this to be lower will lower the quality but increase the performance of the filter.

    1
    
    resources: Record<string, any>

    A record of the resources used by the shader.

    uid: number

    A unique identifier for the shader

    uniforms: {
        uOriginalColor: Float32Array;
        uTargetColor: Float32Array;
        uTolerance: number;
    }
    DEFAULT_OPTIONS: ColorReplaceFilterOptions

    Default values for options.

    defaultOptions: FilterOptions

    The default filter settings

    prefixed: string | boolean
    • get blendMode(): BLEND_MODES

      Get the blend mode of the filter.

      Returns BLEND_MODES

      "normal"
      
    • set blendMode(value: BLEND_MODES): void

      Sets the blend mode of the filter.

      Parameters

      Returns void

    • get epsilon(): number

      Returns number

    • set epsilon(value: number): void

      Parameters

      • value: number

      Returns void

      since 6.0.0

      Tolerance/sensitivity of the floating-point comparison between colors (lower = more exact, higher = more inclusive)

      0.4
      

      ColorReplaceFilter#tolerance

    • get newColor(): DeprecatedColor

      Returns DeprecatedColor

    • set newColor(value: DeprecatedColor): void

      Parameters

      • value: DeprecatedColor

      Returns void

      since 6.0.0

      The resulting color, as a 3 component RGB e.g. [1.0, 0.5, 1.0]

      0x000000
      

      ColorReplaceFilter#targetColor

    • get originalColor(): ColorSource

      The color that will be changed.

      Returns ColorSource

      [1.0, 1.0, 1.0] = 0xffffff
      
      0xff0000
      
    • set originalColor(value: ColorSource): void

      Parameters

      Returns void

    • get targetColor(): ColorSource

      The resulting color.

      Returns ColorSource

      [1.0, 1.0, 1.0] = 0xffffff
      
      0x000000
      
    • set targetColor(value: ColorSource): void

      Parameters

      Returns void

    • get tolerance(): number

      Tolerance/sensitivity of the floating-point comparison between colors (lower = more exact, higher = more inclusive)

      Returns number

      0.4
      
    • set tolerance(value: number): void

      Parameters

      • value: number

      Returns void

    • Type Parameters

      • T extends "destroy"

      Parameters

      • event: T
      • fn: (...args: ArgumentMap<{ destroy: Shader }>[Extract<T, "destroy">]) => void
      • Optionalcontext: any

      Returns this

    • Sometimes a resource group will be provided later (for example global uniforms) In such cases, this method can be used to let the shader know about the group.

      Parameters

      • name: string

        the name of the resource group

      • groupIndex: number

        the index of the group (should match the webGPU shader group location)

      • bindIndex: number

        the index of the bind point (should match the webGPU shader bind point)

      Returns void

    • Applies the filter

      Parameters

      • filterManager: FilterSystem

        The renderer to retrieve the filter from

      • input: Texture

        The input render target.

      • output: RenderSurface

        The target to output to.

      • clearMode: boolean

        Should the output be cleared before rendering to it

      Returns void

    • Use to destroy the shader when its not longer needed. It will destroy the resources and remove listeners.

      Parameters

      • OptionaldestroyPrograms: boolean

        if the programs should be destroyed as well. Make sure its not being used by other shaders!

      Returns void

    • Calls each of the listeners registered for a given event.

      Type Parameters

      • T extends "destroy"

      Parameters

      • event: T
      • ...args: ArgumentMap<{ destroy: Shader }>[Extract<T, "destroy">]

      Returns boolean

    • Return an array listing the events for which the emitter has registered listeners.

      Returns "destroy"[]

    • Return the number of listeners listening to a given event.

      Parameters

      • event: "destroy"

      Returns number

    • Return the listeners registered for a given event.

      Type Parameters

      • T extends "destroy"

      Parameters

      • event: T

      Returns ((...args: ArgumentMap<{ destroy: Shader }>[Extract<T, "destroy">]) => void)[]

    • Type Parameters

      • T extends "destroy"

      Parameters

      • event: T
      • Optionalfn: (...args: ArgumentMap<{ destroy: Shader }>[Extract<T, "destroy">]) => void
      • Optionalcontext: any
      • Optionalonce: boolean

      Returns this

    • Add a listener for a given event.

      Type Parameters

      • T extends "destroy"

      Parameters

      • event: T
      • fn: (...args: ArgumentMap<{ destroy: Shader }>[Extract<T, "destroy">]) => void
      • Optionalcontext: any

      Returns this

    • Add a one-time listener for a given event.

      Type Parameters

      • T extends "destroy"

      Parameters

      • event: T
      • fn: (...args: ArgumentMap<{ destroy: Shader }>[Extract<T, "destroy">]) => void
      • Optionalcontext: any

      Returns this

    • Remove all listeners, or those of the specified event.

      Parameters

      • Optionalevent: "destroy"

      Returns this

    • Remove the listeners of a given event.

      Type Parameters

      • T extends "destroy"

      Parameters

      • event: T
      • Optionalfn: (...args: ArgumentMap<{ destroy: Shader }>[Extract<T, "destroy">]) => void
      • Optionalcontext: any
      • Optionalonce: boolean

      Returns this