17, COCOS2DX 3.0 game development to find small three's built-in frequently used layer: Three Musketeers layercolor, Layergradient, Menu

Source: Internet
Author: User
Tags lua

re-developer of labor results, reproduced when please be sure to indicate the source : http://blog.csdn.net/haomengzhu/article/details/30477587

to facilitate game developers. Cocos2d-x built-in 3 special Layer;details such as the following are seen:Layercolor: A pure solid color block.

layergradient: a color block, but can set the gradient effect of two colors. Menu : Very often used game menus.
the two layers of layercolor and layergradient are very simple and include only one color block. The difference is that the former creates a solid color block, and the latter creates a gradient color block;Take a look at the detailed effect display:



Layercolorhas the following initialization methods:Assuming that the initialization method with the specified width and height is used, a color block of the specified size is created. Assuming that the use does not specifyThe size of the initialization method, creates a screen-sized color block.


The methods of creating and initializing Layercolor are as follows:

    /** creates a fullscreen black layer *    /static layercolor* create ();    /** creates a Layer with color, width and height in Points *    /static Layercolor * Create (const color4b& color, GLf Loat width, glfloat height);    /** creates a Layer with color. Width and height are the window size. *    /Static Layercolor * Create (const color4b& color); Cc_constructor_access:    layercolor ();    Virtual ~layercolor ();        BOOL Init ();    BOOL Initwithcolor (const color4b& color, glfloat width, glfloat height);    BOOL Initwithcolor (const color4b& color);

layergradientSimilar to Layercolor, but it needs to specify two colors and the direction of the gradient when it is initialized.

The number of the starting color. The end parameter is the ending color, and V is the direction vector. layergradient The method of creation and initialization method as seen below:

/** creates a fullscreen black layer */static layergradient* create (); /** creates a full-screen Layer with a gradient between start and end.    */static layergradient* Create (const color4b& start, const color4b& end); /** creates a full-screen Layer with a gradient between start and end in the direction of V. * * static layergradient* C reate (const color4b& Start, const color4b& end, const point& v);    Cc_constructor_access:layergradient ();        Virtual ~layergradient ();    virtual BOOL init ();     /** initializes the Layer with a gradient between start and end.        * @js init * @lua init * */BOOL Initwithcolor (const color4b& Start, const color4b& end);     /** initializes the Layer with a gradient between start and end in the direction of V.  * @js init * @lua init * */BOOL Initwithcolor (const color4b& Start, const color4b& end, const point& V);

after the color block is created, you can also change the color block size by following the methods listed below:
    /** change width in points*/    void Changewidth (glfloat w);    /** change height in points*/    void Changeheight (Glfloat h);    /** change width and height in Points    @since v0.8    *    /void Changewidthandheight (glfloat W, glfloat h);

Menu : Game Menus Menus are an integral part of the game.

in Cocos2d-x, the menu is made up of two parts, each of which is the menu item and itself. MenuItem represents a menu item. Each menu item is a separate button. It defines the visual representation and response action of the menu, which is the menu, which organizes the items into one and adds them to the scene. Transforms the touch events of the screen into individual menu items.


the creation of a menu item usually requires a normal state, a pressed state, a clicked response, and a response method. Below we take a picture menu item as an example to create a dish item, related code such as the following:

  Create a "Close" menu item with close icon, it's an auto release object.  Menuitemimage *pcloseitem = menuitemimage::create (   "closenormal.png",//Picture   "Closeselected.png" in normal state,// Press status picture   Cc_callback_1 (Helloworld::menuclosecallback, this));//Response function and Object  cc_break_if (! Pcloseitem);
callback to the Menuclosecallback function when the button is clicked:Run end game logic: Director::getinstance ()->end ();
Shimen Main Friendship tips:more use of the features provided by the engine, will save a lot of time and energy!

17, COCOS2DX 3.0 game development to find small three's built-in frequently used layer: Three Musketeers layercolor, Layergradient, Menu

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.