To add touch events to a UI (Widget) control that is exported in Cocosstudio in quick cocos2d-x

Source: Internet
Author: User
Tags touch sublime text

The first step: After the project group UI completes the UI control with Cocosstudio, there is a file with the suffix. Xml.ui in it, and double-clicking the file will open the UI.

Step two: Press CTRL + E to change the "sort style" to "Intelligent" and then export.

Step three: Copy the exported files to the Res directory of the project.

Fourth step: In the corresponding interface ctor function, add the following code (the author uses sublime Text 2)

    Local layer = Touchgroup:create ()
    Layer:addwidget (Guireader:sharereader (): Widgetfromjsonfile ("XXXXXXX. Exportjson "))
    self:addchild (layer, 1000)

To run here, you can see a good UI layout.

-------------------------------------------------------Gorgeous split-line------------------------------------------------------------

Fifth Step: Add the following code below the above code:

    SELF.MYBTN = Layer:getwidgetbyname (btnname)--btnname is Cocosstudio, after the control is selected, on the right side of the properties Bar-General, the name
    --self.mybtn: Settouchenabled (True)--NOTE: This statement can be removed because the "interaction" property of the control is set in Cocosstudio.
    Self.myBtn:addTouchEventListener (sender, event)--event is a touch type, 0,1,2,3 is began,moved,ended,canceled
        if event = = 0 Then
			--operation code
            return false
        end
    end)

Note: Refer to http://www.cocoachina.com/bbs/read.php?tid=204622

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.