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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。