`
properties: {
house: {
default: null,
type: cc.Prefab
}
},
onLoad(){
// 生成5X5格子
this.cells = []
for (var x = 0; x<5; x++){
this.cells[x] = []
for (var y = 0; y<5; y++){
// 实例化pretab
var node = cc.instantiate(this.house) // 实例化时, house.type=5
// 获取house插件
var house = node.getComponent('house')
// 修改节点坐标
node.x = 50 * x
node.y = 50 * y
node.pos = cc.p(x,y)
house.pos = cc.p(x,y)
// 诡异? 为什么 house.type 在这里访问一直是0呢?
console.log(house.type)
console.log(house) 打印house.type 数值=5;
this.cells[x][y] = house
this.addTouchEvents(house);
this.node.addChild(node,0,"node");
}
}
},
addTouchEvents: function(house){
house.node.on('touchend', function(event){
// 获取节点位置;
var px = house.pos.x
var py = house.pos.y
// 匹配上一个节点:
// 诡异: 而在这里可以正常访问 = 5
console.log(house.type)
}, this)
},
`