[]如何在游戏入口处获取对象的子对象
在游戏入口实例化玩一个加载TiledMap地图的类(loadMap)后,想通过该对象获取到被加载地图的一个MapLayer层。也就是说,加载TiledMap和获取该地图的MapLayer(某一层)都放到一个类里面,只要通过实例化的对象就能直接调用MapLayer.具体怎么实现呢。获取地图层一定要在_proto.mapLoaaded里面吗?
/***游戏主入口**
* name;
*/
var TiledMap = Laya.TiledMap;
var Rectangle = Laya.Rectangle;
var Handler = Laya.Handler;
var Sprite = Laya.Sprite;
var MapLayer = Laya.MapLayer;
var loadMap = (function (_super) {
function loadMap() {
loadMap.super(this);
}
Laya.class(loadMap,"loadMap",_super);
var _proto = loadMap.prototype;
_proto.init = function() {
this.num = "";
this.map = new TiledMap();
}
_proto.showMap = function(num) {
this.num = num;
this.map.createMap("map/level/mota_map" + num + ".json",new Rectangle(0,0,448,448),Handler.create(this,this.mapLoaded));}
_proto.mapLoaded = function(){
this.pass = this.map.getLayerByIndex(0);//获取通行层
console.log(this.pass);
}
_proto.getLayer = function() {
this.floor = this.map.getLayerByIndex(0);//获取通行层
console.log(this.pass);
}
console.log(this.map)
return loadMap;
})(Sprite);
var Main = (function (){
(function Main(){
Laya.init(448,448);
var map1 = new loadMap();
map1.init();
map1.showMap("3");
map1.getLayer();
console.log(map1.num);
console.log(map1);
console.log(map1.pass);
console.log(map1.getLayer);
})();
return Main;
})();
没有找到相关结果
已邀请:
要回复问题请先登录
1 个回复
cuixueying
赞同来自: