请教一下
为什么会出这个错呢
我环境是
cocoscreater 1.9.0
调试的浏览器的 Google Chrome
TypeScript 脚本写的一个类加载地图文件
代码如下
// 主场景 加载
protected onLoad()
{
this.m_GameLog = new GameLog();
// 初始化输入监听
this.addEventListeners();
this.m_GameMap = new GameMap();
let tiledMapUrl = 'map/map1';
this.AddNewGameMap(tiledMapUrl);
//this.onLoadTiledMap(tiledMapUrl);
}
private AddNewGameMap(url: string)
{
this.m_GameMap.InitGameMap(url, () =>{
let node = this.m_GameMap.GetGameMap();
let layoutmap = this.node.getChildByName('LayoutMap');
if(layoutmap != null)
{
layoutmap.addChild(node);
node.setAnchorPoint(cc.p(0, 0));
node.setPosition(cc.p(0, 0));
}
});
}
======================
// GameMap 类 加载函数
private m_MapNode: cc.Node = null;
// TiledMap 对象
private m_GameMap: cc.TiledMap = null;
// 构造函数
constructor(){
this.m_GameLog = new GameLog();
this.m_MapNode = new cc.Node();
this.m_GameLog.PrintLog('GameMap => GameMap');
}
public InitGameMap(url: string, callback: () => void)
{
// 回调函数不能分开写 必须用 => 这个方法重新定义内部函数
cc.loader.loadRes(url, cc.TiledMapAsset, (error: Error, resource: any) =>{
if(error)
{
this.m_GameLog.PrintError('GameMap => InitGameMap' + error.message);
}else{
this.m_GameMap = this.m_MapNode.addComponent(cc.TiledMap);
this.m_GameMap.tmxAsset = resource;
this.InitTiledMapObject();
callback();
}
})
}
public GetGameMap()
{
return this.m_MapNode;
}
、、、、
上面的代码跑起来, 是可以显示出地图的,也没有什么色块的偏差
可问题就是为什么会上面的那些错呢,我哪里写错了吗,
请指教 谢谢
我现在都不敢向下写了,唉。。。。。
