1. cclayercolor is a layer used to process the background color. It inherits from cclayer and can be used to set the background color of the layer, because cclayer is transparent by default, that is, non-color
2. cclayergradient is a layer used to display the color gradient effect. It inherits from cclayercolor and is the sun class of cclayer.
3. Several special layers: cclayercolor, cclayergradient
Color layers are mainly used to set the background in the game. You can set the fill color according to RGB, and set the transparency of the layer, which is often used in the background.
The color layer also has a special subclass: cclayergradient, which is a color layer with a gradient effect.
You can set the gradient effect of the background, opacity: Transparency
4. related processing functions:
Bool cclayercolor: initwithcolor (const cccolor4b & color );
Bool cclayercolor: initwithcolor (const cccolor4b & color, glfloat W, glfloat H );
Instance:
Cclayercolor: initwithcolor (ccc4 (255,255,255,255 ));
Cclayercolor: initwithcolor (ccc4 (255,255,255,255), 100,100 );
Ignoreanchorpointforposition (false );
Bool cclayergradient: initwithcolor (const cccolor4b & START, const cccolor4b & End );
Bool cclayergradient: initwithcolor (const cccolor4b & START, const cccolor4b & End, const ccpoint & V );
Instance:
Cclayergradient: initwithcolor (ccc4 (123,89, 0,255 ),
Ccc4 (0,255,255,255), CCP ));
5. Code implementation:
. H file
# Ifndef _ t04colorlayer_h __# DEFINE _ t04colorlayer_h __# include "cocos2d. H "using_ns_cc;/* the Default background color of the cclayer is transparent, while that of the cclayercolor layer can be set to the background color */class t04colorlayer: Public cclayercolor {public: static ccscene * scene (); create_func (t04colorlayer); bool Init () ;};# endif
. Cpp File
# Include "t04colorlayer. H "/* cclayergradient can set gradient of color, class cclayergradient: Public cclayercolor */class layergradient: Public cclayergradient {public: create_func (layergradient); bool Init () {/** initializes the cclayer with a gradient between start and end in the direction of v. virtual bool initwithcolor (const cccolor4b & START, const cccolor4b & End, const ccpoint & V); **/cclayergradient: initwithcolor (ccc4 (255,255, 0,255), ccc4 (0, 0,255,255), CCP (1, 0); Return true ;}}; ccscene * t04colorlayer: Scene () {ccscene * scene = ccscene: Create (); /* test background layer */t04colorlayer * layer = t04colorlayer: Create ();/* test gradient layer * // layergradient * layer = layergradient: Create (); scene-> addchild (layer); Return scene;} bool t04colorlayer: Init () {cclayercolor: initwithcolor (ccc4 (255, 0,255,255), 200,200 ); /* set not to ignore the anchor. By default, the anchor is ignored in cclayer and ccscene. */ignoreanchorpointforposition (false); Return true ;}
Cclayercolor and gradient layer cclayergradient in cocos2dx