我在书上看的《cocos2d-x实战》:
var HelloWorldLayer = cc.Layer.extend({
ctor:function () {
this._super();
var layerColor = new cc.LayerColor(cc.color(255,255,255));
this.addChild(layerColor, 0,0);
var plane = new cc.Sprite(res.plane);
plane.x = 300;
plane.y = 400;
plane.scaleX = 0.5;
plane.scaleY = 0.5;
this.addChild(plane,10,ActionTypes.BOY_TAG);
return true;
},
onEnter:function(){
this._super();
var tt = this.getChildByTag(ActionTypes.BOY_TAG);//ActionTypes.BOY_TAG是常量,为数字100
var listener = cc.EventListener.create(
{
event:cc.EventListener.MOUSE,
onMouseDown:function(event){
alert(5)//点击plane物体,触发输出5;
}
}
)
cc.eventManager.addListener(listener,tt);
}
});
可是这个做法,并不是点击plane这个物体触发,而是点击任何地方都触发,请问哪里出错了呢?