The current scene.
The bands which make up this ramp. This can be one entry or an array, and can be configs or existing instances. A band count over 1048576 may be unsafe.
OptionalgpuEncode: boolean
Whether to create a data texture to use this ramp in shaders. Default true.
The color bands that make up this ramp.
ReadonlybandThe number of levels in the band tree. This is used internally to decode the data texture.
ReadonlydataThe Phaser Texture wrapping the GPU data texture for this ramp. This is registered with the Scene's Texture Manager under a unique key so it can be referenced elsewhere. It is not intended for display.
ReadonlydataThe texel index which contains the first band data
in glTexture if it has been encoded.
This is used internally.
ReadonlydataThe resolution of the data texture, if it has been encoded. This is used internally.
ReadonlyglThe texture containing the ramp encoded for the GPU. This is used internally by effects such as the Gradient game object to read complex ramp data.
Whether to encode the ramp for shaders to use on the GPU. An encoded ramp is stored as a texture.
ReadonlysceneThe scene where the ColorRamp was created.
Destroy this ColorRamp. If it has a data texture, destroy it.
Encode a data texture from the color ramp bands.
This process runs automatically when gpuEncode is enabled
and the bands are set or updated with setBands.
If you modify the bands directly, you must call encode yourself.
The data is encoded in texels as follows:
Numbers are encoded in "RG.BA" form. The number equals R * 255 + G + B / 255 + A / 255 / 255.
dataTextureFirstBand:
the band data, in blocks of 3:
The binary symmetrical tree breaks the bands list in half with every node. It is intended to quickly find the band corresponding to a given progress along the ramp. For example, a ramp with 10 bands would store the ends in this order:
[ 7, 3, 11, 1, 5, 9, 13, 0, 2, 4, 6, 8, 10, 12, 14 ]
But because it doesn't have bands from index 10 and up, it's actually:
[ 7, 3, 9, 1, 5, 9, 9, 0, 2, 4, 6, 8, 9, 9, 9 ]
Note that, if you change the number of bands in the ramp,
dataTexture may no longer have the correct resolution.
It is not intended for display.
Fix the fit of bands within this ColorRamp.
This sets the start of each band to the end of the previous band, ensuring that there are no gaps.
Optionally, you can define start and end values to stretch the ramp to some specific range, e.g. 0-1.
By default, any band that is now 0 length will be removed.
Override the start of the first band.
Override the end of the last band.
Whether to discard bands that now have 0 size.
Whether to reencode the data texture.
Get the color value at the given index within this ramp.
If there is no band at that location, the color is transparent.
Index of the color to get, from 0 (start) to 1 (end).
The color at that index.
Set or replace the color bands in this ramp. Use this after creation to update the bands.
This will re-encode the data texture if gpuEncode is set
and encode is not false.
The bands to make up this ramp. This can be one entry or an array, and can be configs or existing instances.
Optionalencode: boolean
Whether to encode the new ramp data to a data texture for use in shaders. Default true.
Split a band from this ramp into several bands, and insert them into the ramp.
You can choose whether to "quantize" the bands, where each of them has a flat color.
The band to split, either an index on this ramp or the band instance. The band must be on this ramp.
The number of bands to create.
Optionalquantize: boolean
Whether to quantize the bands to a single color. Default false.
Optionalencode: boolean
Whether to rebuild the data texture. Default true.
This ColorRamp instance.
The ColorRamp class represents a series of color transitions. It is intended for use in a {@see Phaser.GameObjects.Gradient}.
You should make sure that your bands are arranged end-to-end, with no gaps. The Gradient shader assumes this is so. You may leave gaps at the start and end. Overlaps and gaps may not act as expected.
By default, ColorRamp stores its data for use on the GPU in a data texture. This is updated automatically on creation and when you run
setBands(), but if you edit the bands manually, you should runencode()to rebuild the texture. We don't update it automatically because we don't want to waste cycles on rebuilds that you're about to overwrite.