var Test = cc.Layer.extend({
ctor:function(){
this._super();
var size = cc.winSize;
this.sprite = new cc.Sprite();
this.sprite.attr({
x : size.width/2,
y : size.height/2,
anchorX : 0.5,
anchorY : 0.5,
width : 320,
height : 400
});
this.addChild(this.sprite, 0);
this.initChessman();
this.log(size.width, size.height);
return true;
},
initChessman:function()
{
for(var i = 0; i<5 ; i++){
for (var j = 0; j < 5; j++) {
var sprite = new cc.Sprite(res.Hand_jpg);
sprite.attr({
x : (cc.winSize.width - 320)/2 + 80i,
y : (cc.winSize.height - 400)/2 +100j,
scale : 0.05
});
this.addChild(sprite);
var listener = cc.EventListener.create({
event : cc.EventListener.TOUCH_ONE_BY_ONE,
swallowTouches : true,
onTouchBegan : function(touch,event){
var target = event.getCurrentTarget();
var locationInNode = target.convertToNodeSpace(touch.getLocation());
var s = target.getContentSize();
var rect = cc.rect(0, 0, s.width, s.height);
if (cc.rectContainsPoint(rect, locationInNode)) {
cc.log(“click”);
return true;
}
return false;
}
});
cc.eventManager.addListener(listener, sprite);
// this.log(sprite.x,sprite.y);
}
}
},
log : function (x,y) {
cc.log(“Test!%d,%d”,x,y);
}
});
我想做一个5乘5的节点矩阵,点击其中每个节点都会打印“click”日志。但是现在矩阵的头两行和第三行第一列的节点都不会响应事件,但是其余的节点就会。我已经纠结一天了,求指导,求拯救。