Creates a new gradient fill. The constructor behavior changes based on the gradient type.
The options for the gradient
The center point of the inner circle of the radial gradient
Array of color stops defining the gradient
The end point of the linear gradient
The radius of the inner circle of the radial gradient
The center point of the outer circle of the radial gradient
The radius of the outer circle of the radial gradient
The rotation of the radial gradient
The scale of the radial gradient
The start point of the linear gradient
Internal texture used to render the gradient
Whether gradient coordinates are in local or global space
Transform matrix for positioning the gradient
Readonly
typeType of gradient - currently only supports 'linear'
Static
Readonly
defaultDefault options for creating a gradient fill
Static
Readonly
defaultDefault options for creating a radial gradient fill
Gets a unique key representing the current state of the gradient. Used internally for caching.
Unique string key
Adds a color stop to the gradient
Position of the stop (0-1)
Color of the stop
This gradient instance for chaining
Class representing a gradient fill that can be used to fill shapes and text. Supports both linear and radial gradients with multiple color stops.
For linear gradients, color stops define colors and positions (0 to 1) along a line from start point (x0,y0) to end point (x1,y1).
For radial gradients, color stops define colors between two circles - an inner circle centered at (x0,y0) with radius r0, and an outer circle centered at (x1,y1) with radius r1.
Example
Internally this creates a texture of the gradient then applies a transform to it to give it the correct size and angle.
This means that it's important to destroy a gradient when it is no longer needed to avoid memory leaks.
If you want to animate a gradient then it's best to modify and update an existing one rather than creating a whole new one each time. That or use a custom shader.