quick-cocos2d-x3.3 Study (Fri)---------Add button

Source: Internet
Author: User

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

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.