Cc. Button
1: Add button Method
(1) directly create a node with a button component;
(2) create a node before adding a component;
2: button components. Buttons are the most commonly used components in the game. Click them to respond to events;
3: button transition effect:
Transition: normal state, move the mouse to the object, press the state, disable the state
(1) No transition, only response to events;
(2) color transition. colors are used in the transition effect;
(3) genie transition, using image transition;
(4) zoom transition, option, whether to set the gray when disable;
4: the button is disabled;
5: click the button to add a response event --> node --> component --> code function;
6: The button passes custom parameters; ---> String object;
7: The button responds to this touch. Therefore, the node to which the button is attached must have a size. If you open a button to a node of the size (0, 0, this event does not respond to the click event;
The Code uses cc. Button
1: Add/obtain the CC. Button component in the Code;
2: Add button response events in the Code;
3: return function specified by the Code trigger button;
4: component. eventhandler
VaR eventhandler = new CC. component. eventhandler ();
Eventhandler.tar get = newtarget;
Eventhandler. Component = "mainmenu ";
Eventhandler. Handler = "onclick ";
Eventhandler. customeventdata = "my data ";
Eventhandler. emit (["param1", "param2",...]);
// Use this for initialization onload: function () {// obtain the button component this. start_button = This. node. getchildbyname ("ks_up "). getcomponent (CC. button); // Add the button component this. red_button = This. node. getchildbyname ("red_button "). addcomponent (CC. button); // Add a response function var click_event = new CC. component. eventhandler (); click_event.target = This. node; click_event.component = "game_scene"; click_event.handler = "on_red_button_click"; click_event.customeventdata = "red_button_data_77777"; // This. red_button.clickevents = [click_event]; this. red_button.clickevents.push (click_event); // end // The RESPONSE event of the Code trigger button, instead of touching this. scheduleonce (function () {var click_events = This. red_button.clickevents; For (VAR I = 0; I <click_events.length; I ++) {var comp_env_handle = click_events [I]; // The Response Function comp_env_handle.emit (["", "red_button_data_6666"]) that triggers the button in the Code;}. BIND (this), 3); // end}, on_red_button_click: function (E, custom) {console. log ("on_red_button_click:", custom) ;}, // The level button 1-10, the nth mark // e the touch event of this touch // customeventdata is string; on_button_click: function (E, level) {// level = parseint (level); console. log ("on_button_click called:", level) ;}, btn1_click: function () {console. log ("This Is button click ");},
Cc. Button