Quick Cocos2dx-lua (V3.3R1) Learning notes (13)-----Continue to touch event multi-touch

Source: Internet
Author: User

In front, we mentioned a single touch, below we try the use of multi-touch (I use the Cocos code IDE for phone debugging, no, into the previous review)

function mainscene:ctor ()     = Display.newsprite ("Close.png")-   - Find yourself an image resource    sprite:align (display. CENTER, Display.cx, display.cy)    sprite:addto (self)    sprite:settouchenabled (true)                            Sprite:settouchmode (CC. touches_all_at_once)           function  (event)          dump (event)             return true     end) End

As long as the Settouchmode fill in the multi-touch on the line, if we do not know in the beginning what this event, we first dump him, to see if there is in him. Run on the PC, click to see

We see the console output, see Points is a table, our computer mouse can only a single point, the output of points[0] information,

In multi-touch, it also has a added,removed two unique events.

functionmainscene:ctor () local layer=Display.newlayer () layer:addto (self) layer:settouchenabled (true) Layer:settouchmode (CC. touches_all_at_once) Layer:addnodeeventlistener (CC. Node_touch_event,function(Event)ifEvent.name = = "began"Then print ("Touch Start") ElseIf Event.name= = "added"Then print ("added a touch point")ElseIf event.name= = "Moved"Then ElseIf event.name= = "Removed"Then print ("Remove a touch point") ElseIf Event.name= = "Ended"Then print ("Touch End") Endreturn trueend) End

Connecting the Android device debug output

I put five fingers up, see this debugging information, event trigger order, you can see, the first point is the touch start, the back slowly increased, to the back of the finger left the screen, is a reduction, below we will filter the third point, when we touch the third point, the output of a message

functionmainscene:ctor () local layer=Display.newlayer () layer:addto (self) layer:settouchenabled (true) Layer:settouchmode (CC. touches_all_at_once) Layer:addnodeeventlistener (CC. Node_touch_event,function(Event)ifEvent.name = = "began"Then print ("Touch Start") ElseIf Event.name= = "added"Then print ("added a touch point")            if"Table" = = Type (event.points["2")] Then print ("Three-point touch") End ElseIf Event.name= = "Removed"Then print ("Remove a touch point") ElseIf Event.name= = "Ended"Then print ("Touch End") Endreturn trueend) End

To the phone above the output

We saw that the third cell phone put up, appeared three touch words, notice, event.point inside the table index starting from 0, the second point is event.point["1". Note that you cannot write event.point[1], so that printing information will not appear.

Quick Cocos2dx-lua (V3.3R1) Learning notes (13)-----Continue to touch event multi-touch

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.