新手求解答 关于ccjs 事件问题

var createSpr = cc.Sprite.extend({
ctor:function(res,x,y,name){
this._super();
this.initWithFile(res)
this.x = x;
this.y = y;
this.name = name;

cc.eventManager.addListener({
event: cc.EventListener.TOUCH_ONE_BY_ONE,
swallowTouches: true,
onTouchBegan: this.onTouchBegan,
onTouchMoved: this.onTouchMoved,
onTouchEnded: this.onTouchEnded
}, this);
},
onTouchBegan:function(touch, event){
return true;
},
onTouchMoved:function(touch, event){
var target = event.getCurrentTarget();
var pos = touch.getLocation();
var locationInNode = target.convertToNodeSpace(pos);
var s = target.getContentSize();
var rect = cc.rect(0, 0, s.width, s.height);
if(cc.rectContainsPoint(rect, locationInNode)){
target.x = pos.x;
target.y = pos.y;
}
},
onTouchEnded:function(touch, event){

}

});

这样的代码下来 在主场景 for循环几个精灵

if(true){
for(var i=0;i<3;i++){
sprObj* = new spr(this,res.n1m,xy*,xy*,i);
this.addChild(sprObj*,i,i)
}
}

最后 只有 第三个精灵是有事件的。
求解答 是什么原因


因为你ontouchbegan强制return true了, 要改成ontouchmove的写法。没在范围内。return false;

我的问题是,我新建的这个类,用for循环new 出来之后 只有最后i一个生成的精灵才具有事件。然而一个一个生成的话,就每个都可以有事件了。新手,求多多指教

都跟你说了。不是最后一个精灵事件才有效。是因为你事件写错了。所以才变成这样的。不能强制return true,否则其它精灵收不到事件的。

自己捣鼓了几天,发现问题了。谢谢你的回答