用的是window机,所以用的是真机测试
var g_HelloWorldLayer;
var HelloWorldLayer = cc.Layer.extend({
AllAtOnce:null,
sprite:null,
ctor:function () {
this._super();
g_HelloWorldLayer = this;
this.adds();
this.addss();
this.addssss();
this.init();
return true;
},
init: function () {
this.AllAtOnce = cc.eventManager.addListener({//事件管理器,增加监听器
event: cc.EventListener.TOUCH_ALL_AT_ONCE,
//swallowTouches: true,//时间穿透,不允许点击当前对象的下一对象
onTouchesBegan: this.onTouchesBegan,
onTouchesMoved: this.onTouchesMoved,
onTouchesEnded: this.onTouchesEnded,
onTouchesCancelled: this.onTouchesCancelled
}, this);
// cc.eventManager.setPriority(AllAtOnce, 2);
// this.AllAtOnce.setEnabled(true);
// this.AllAtOnce.retain();
},
/**
* 测试
/
addssss: function () {
this.txttt = new cc.LabelTTF(“测试”, “”, 18);
this.txttt.attr({
x: 10,
y: 300,
anchorX: 0,
anchorY: 1
});
this.addChild(this.txttt, 100);
},
addss: function () {
this.txt2 = new cc.LabelTTF(“测试”, “”, 18);
this.txt2.attr({
x: 10,
y: 100,
anchorX: 0,
anchorY: 1
});
this.addChild(this.txt2, 100);
},
adds: function () {
this.txt3 = new cc.LabelTTF(“测试”, “”, 18);
this.txt3.attr({
x: 10,
y: 200,
anchorX: 0,
anchorY: 1
});
this.addChild(this.txt3, 100);
},
onTouchesBegan: function (touches, event) {
var x = ];
var y = ];
g_HelloWorldLayer.txttt.setString(“len:” + touches.length);//显示触摸长度
for (var i = 0; i < touches.length; i++) {
var touch = touches;
var pos = touch.getLocation();
x* = pos.x;
y* = pos.y;
cc.log(“Touch #” + i + ". onTouchesBegan at: " + pos.x + " " + pos.y);
g_HelloWorldLayer.txttt.setString("len:" + touches.length + "Touch #" + i + ". onTouchesBegan at: " + pos.x + " " + pos.y);//第i个点
}
g_HelloWorldLayer.txt2.setString("Touch # . onTouchesBegan at: " + x + " " + y);//第一个点
g_HelloWorldLayer.txt3.setString("Touch # . onTouchesBegan at: " + x + " " + y);//第二个点
}
});
求解决…