1.首先定义监听事件
var touchListener_Sprite_touxiang_pic = cc.EventListener.create({//自己
event: cc.EventListener.TOUCH_ONE_BY_ONE,
swallowTouches:true,
onTouchBegan: function(touch, event){
return true;//必须 return true
}.bind(this),
onTouchEnded: function(touch, event){
var target = event.getCurrentTarget();
var locationInNode = target.convertToNodeSpace(touch.getLocation());
if(locationInNode.x >= m_this.Pro_left_touxiang.getPositionX() &&
locationInNode.y >= m_this.Pro_left_touxiang.getPositionY() &&
locationInNode.x <= (m_this.Pro_left_touxiang.getPositionX()+130) &&
locationInNode.y <= (m_this.Pro_left_touxiang.getPositionY()+190))// 判断之后执行的操作
{
m_this.spriteMsgUserLeftListen();
}
}
});
2.定义一个sprite,并将它和监听事件绑定,
this.Sprite_touxiang_pic_left = ccui.helper.seekWidgetByName(this.Pro_left_touxiang, "Sprite_touxiang_pic");
cc.eventManager.addListener(touchListener_Sprite_touxiang_pic, this);
具体可参考Samples里的 NewEventManagerTest