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