我在背景图片上面添加点击事件,然后将在背景上面的点击坐标。抛到防御塔的JS文件里面让他接收并获取坐标
背景JS代码:
cc.Class({
extends: cc.Component,properties: {
paota:{
default: null,
type: cc.Node
}
},
onLoad: function () {
this.init();
},
init:function(){
var that = this
var listener = {
event: cc.EventListener.TOUCH_ONE_BY_ONE,
onTouchBegan: function (touches, event) {
that.paota.getComponent("paota")._init(touches.getLocation())
return true;
},
onTouchMoved: function (touches, event) {
},
onTouchEnded: function (touches, event) {
}
}
// 绑定单点触摸事件
cc.eventManager.addListener(listener, this.node);
}
});
然后在背景的属性检查器里面将在层级管理器中的防御塔导入进去
防御塔JS代码:
cc.Class({
extends: cc.Component,
_init:function(data){
DATA即为接收到的点击坐标
},