ccc 多点触控2

时间:2023-04-11 21:28:44
经过不断的思考发现,如果是两个sprite都添加触控的时候,往往直接成单点触控,
但是如果是两个node的时候在node上面点击就会变成多点触控的形式
cc.Class({
extends: cc.Component, properties: {
isAPress:false,
aLabel:
{
default:null,
type :cc.Label
}
}, // use this for initialization
onLoad: function () { this.isAPress=false this.registerInput(); }, registerInput:function()
{
var self=this cc.eventManager.addListener({
event: cc.EventListener.TOUCH_ONE_BY_ONE, //开始
onTouchBegan: function(touch, event) { let touchPos=touch.getLocation()
if(touchPos.x<480)
{
self.isAPress=true
}
return true; // don't capture event
}, //移动
onTouchMoved: function(touch, event) {
let touchPos=touch.getLocation()
if(touchPos.x<480)
{
self.isAPress=true
}
}, //结束
onTouchEnded: function(touch, event) {
self.isAPress=false
}
}, self.node);
}, update:function()
{
if(this.isAPress)
{
this.aLabel.string = "1"
}
else
{
this.aLabel.string = "0"
}
}, });