start: function () {
//var layout = this.node.getChildByName("havetile");
var map = this.node.getComponent(cc.TiledLayer);
var tiles = map.getTiles(); //这里获取不到tiles 为undefined
for (var i in tiles) {
var bnot = tiles[i];
if (bnot == 0) {
var pos = map.getPositionAt(this.getPosByIndex(i))
var num = this.pre.length;
var r = Math.ceil(Math.random()*(num-1)*num);
var pre = this.pre[r-1];
var nd = cc.instantiate(pre);
nd.parent = this.node;
nd.x = pos.x;
nd.y = pos.y;
}
}
},
// called every frame, uncomment this function to activate update callback
update: function (dt) {
if (this.bload == false) {
var map = this.node.getComponent(cc.TiledLayer);
var tiles = map.getTiles();//这里需要跳几帧后才能获取到tile
for (var i in tiles) {
this.bload = true;
var bnot = tiles[i];
if (bnot == 0) {
var pos = map.getPositionAt(this.getPosByIndex(i))
var num = this.pre.length;
var r = Math.ceil(Math.random()*(num-1)*num);
var pre = this.pre[r-1];
var nd = cc.instantiate(pre);
nd.parent = this.node;
nd.x = pos.x;
nd.y = pos.y;
}
}
}
else{
var map = this.node.getComponent(cc.TiledLayer);
var tiles = map.getTiles();
}
},
跟踪源码发现在渲染到tilemap的时候才调用cc.loader.load来获取tmx文件,这个有什么解决办法吗
