Class cc.LayerGradient
- Defined in: CCLayer.js
- Extends cc.LayerColor
Constructor Attributes | Constructor Name and Description |
---|---|
cc.LayerGradient(start, end, v)
CCLayerGradient is a subclass of cc.LayerColor that draws gradients across the background. |
Method Summary
Class Detail
cc.LayerGradient(start, end, v)
CCLayerGradient is a subclass of cc.LayerColor that draws gradients across the background.
All features from cc.LayerColor are valid, plus the following new features:
- direction
- final color
- interpolation mode
Color is interpolated between the startColor and endColor along the given
vector (starting at the origin, ending at the terminus). If no vector is
supplied, it defaults to (0, -1) -- a fade from top to bottom.
If 'compressedInterpolation' is disabled, you will not see either the start or end color for
non-cardinal vectors; a smooth gradient implying both end points will be still
be drawn, however.
If 'compressedInterpolation' is enabled (default mode) you will see both the start and end colors of the gradient.
Field Detail
{Number}
compressedInterpolation
- Indicate whether or not the interpolation will be compressed
{cc.Color}
endColor
- End color of the color gradient
{Number}
endOpacity
- End opacity of the color gradient
{cc.Color}
startColor
- Start color of the color gradient
{Number}
startOpacity
- Start opacity of the color gradient
{Number}
vector
- Direction vector of the color gradient
Method Detail
-
Creates a gradient layer
- Parameters:
- {cc.Color} start
- starting color
- {cc.Color} end
- ending color
- {cc.Point|Null} v
- {Array|NULL} stops
- Deprecated:
- since v3.0, please use the new construction instead
- Returns:
- {cc.LayerGradient}
- See:
- cc.layerGradient
-
ctor(start, end, v, stops)Constructor of cc.LayerGradient
Using ColorStops argument: //startColor & endColor are for default and backward compatibility var layerGradient = new cc.LayerGradient(cc.color.RED, new cc.Color(255,0,0,0), cc.p(0, -1), [{p:0, color: cc.color.RED}, {p:.5, color: new cc.Color(0,0,0,0)}, {p:1, color: cc.color.RED}]); //where p = A value between 0.0 and 1.0 that represents the position between start and end in a gradient
-
{Array} getColorStops()Return an array of Object representing a colorStop for the gradient, if no stops was specified start & endColor will be provided as default values
[{p: 0, color: cc.color.RED},{p: 1, color: cc.color.RED},...]
- Returns:
- {Array}
-
{cc.Color} getEndColor()Returns the end color
- Returns:
- {cc.Color}
-
{Number} getEndOpacity()Returns the end gradient opacity
- Returns:
- {Number}
-
{cc.Color} getStartColor()Returns the starting color
- Returns:
- {cc.Color}
-
{Number} getStartOpacity()Returns the starting gradient opacity
- Returns:
- {Number}
-
{cc.Point} getVector()Returns the direction vector of the gradient
- Returns:
- {cc.Point}
-
{Boolean} init(start, end, v, stops)Initialization of the layer, please do not call this function by yourself, you should pass the parameters to constructor to initialize a layer
- Returns:
- {Boolean}
-
{Boolean} isCompressedInterpolation()Returns whether compressed interpolation is enabled
- Returns:
- {Boolean}
-
setColorStops(colorStops)Set the colorStops to create the gradient using multiple point & color
//startColor & endColor are for default and backward compatibility var layerGradient = new cc.LayerGradient(cc.color.RED, new cc.Color(255,0,0,0), cc.p(0, -1)); layerGradient.setColorStops([{p:0, color: cc.color.RED}, {p:.5, color: new cc.Color(0,0,0,0)}, {p:1, color: cc.color.RED}]); //where p = A value between 0.0 and 1.0 that represents the position between start and end in a gradient
- Parameters:
- colorStops
-
setCompressedInterpolation(compress)Sets whether compressed interpolation is enabled
- Parameters:
- {Boolean} compress
-
setContentSize(size, height)Sets the untransformed size of the LayerGradient.
- Parameters:
- {cc.Size|Number} size
- The untransformed size of the LayerGradient or The untransformed size's width of the LayerGradient.
- {Number} height Optional
- The untransformed size's height of the LayerGradient.
-
setEndColor(color)Sets the end gradient color
// Example myGradientLayer.setEndColor(cc.color(255,0,0)); //set the ending gradient to red
- Parameters:
- {cc.Color} color
-
setEndOpacity(o)Sets the end gradient opacity
- Parameters:
- {Number} o
-
setStartColor(color)Sets the starting color
// Example myGradientLayer.setStartColor(cc.color(255,0,0)); //set the starting gradient to red
- Parameters:
- {cc.Color} color
-
setStartOpacity(o)Sets starting gradient opacity
- Parameters:
- {Number} o
- from 0 to 255, 0 is transparent
-
setVector(Var)Sets the direction vector of the gradient
- Parameters:
- {cc.Point} Var