Add button
1.
1 --Add a button2Cc.ui.UIPushButton.new ({normal ="Image/button/start1.png", pressed ="Image/button/start2.png" } )3 --Click4 : onbuttonclicked (5 function ()6 Print("----The Start button is onclicked----") 7 End8 )9 --Press theTen : onbuttonpressed ( One function () A Print("----The Start button is onpressed----") - End - ) the --Release - : Onbuttonrelease ( - function () - Print("----The Start button is onrelease----") + End - ) + --the state of the button changes A : onbuttonstatechanged ( at function () - Print("----The Start button is onstatechanged----") - End - ) - --location - :p os (display.cx, display.cy) in --Add -: AddTo (self)
2.
1 --Add a Checkboxbutton button2Cc.ui.UICheckBoxButton.new ({off ="Image/button/checkbox_off.png", on ="Image/button/checkbox_on.png" } )3 --Click4 : onbuttonclicked (5 function ()6 Print("----The CheckBox is onclicked----" )7 End8 )9 --Press theTen : onbuttonpressed ( One function ( ) A Print("----The CheckBox is onpressed----") - End - ) the --Release - : Onbuttonrelease ( - function () - Print("----The CheckBox is onrelease----") + End - ) + --the state of the button changes A : onbuttonstatechanged ( at function () - Print("----The CheckBox is onstatechanged----") - End - ) -:p OS (DISPLAY.CX *0.3, display.cy) -: AddTo (self)
There are three different button controls in quick,
are: UIPushButton (Button control),
Uicheckboxbutton (Checkbutton control) and
Uicheckboxbuttongroup (Checkbutton Group control).
UIPushButton is the most commonly used button control, it inherits from the UIButton,
We can create UIPushButton through the cc.ui.UIPushButton.new (images, options) method.
The parameter images is the table type, which represents the picture under each button state (normal, pressed, disabled);
Options are optional parameters and are tabl e types that contain settings such as scale9 scaling, offset flipx, flipy values, and so on.
The OnButtonClicked method is used to listen for a button's click event, and the code in the method is called when the button is clicked.
Onbuttonpressed (CALLBACK): Press event for the Listener button
Onbuttonrelease (CALLBACK): Release event for the Listener button
Onbuttonstatechanged (callback): Status Change event for the listener button
:
1. Effect and output without clicking start
2. Click on the effect and output after start not release
3. Click on the effect and output after start release
4. Click after checkbox and output
5. Click and output again after the checkbox
quick-cocos2d-x3.3 Study (Fri)---------Add button