[LayaAirIDE 2.0]使用TiledMap 创建地图之后, 没有展示出来, 回调方法也没有进入

 
// 游戏主体场景
export default class MainGameScene extends SingleScene { 
    // 当前场景的实例名, 可以用这个值从 SingleManager 中获取当前实例, 前提是已经注册了
    public static SINGLE_KEY: string = "single_scene_game";

    private tiledMap: TiledMap;
    private mLastMouseX: number = 0;
    private mLastMouseY: number = 0; 
    private mX: number = 0;
    private mY: number = 0; 
    
    constructor() {
        super(MainGameScene.SINGLE_KEY);
        
        Laya.stage.scaleMode = Stage.SCALE_FULL;
        Stat.show(); 
        this.createMap(); 
        Laya.stage.on(Laya.Event.MOUSE_DOWN, this, this.mouseDown);//注册鼠标事件
        Laya.stage.on(Laya.Event.MOUSE_UP, this, this.mouseUp); 
    }
    //创建地图
    private createMap() {
        //创建地图对象
        this.tiledMap = new TiledMap(); 
        this.mX = this.mY = 0;
        //创建地图,适当的时候调用destory销毁地图
        this.tiledMap.createMap("tilemap/map.json", new Rectangle(0, 0, Browser.width, Browser.height), new Handler(this, this.completeHandler));
        // this.tMap.createMap("tilemap/map.json", viewRect, Laya.Handler.create(this,this.onMapLoaded));
    } 
    /**
     * 地图加载完成的回调
     */
    private completeHandler(): void {
        console.log("地图创建完成");
        console.log("ClientW:" + Browser.clientWidth + " ClientH:" + Browser.clientHeight);
        Laya.stage.on(Laya.Event.RESIZE, this, this.resize);
        this.resize();
    } 
    //鼠标按下拖动地图
    private mouseDown(): void {
        this.mLastMouseX = Laya.stage.mouseX;
        this.mLastMouseY = Laya.stage.mouseY;
        Laya.stage.on(Laya.Event.MOUSE_MOVE, this, this.mouseMove);
    } 
    private mouseMove(): void {
        //移动地图视口
        this.tiledMap.moveViewPort(this.mX - (Laya.stage.mouseX - this.mLastMouseX), this.mY - (Laya.stage.mouseY - this.mLastMouseY));
    } 
    private mouseUp(): void {
        this.mX = this.mX - (Laya.stage.mouseX - this.mLastMouseX);
        this.mY = this.mY - (Laya.stage.mouseY - this.mLastMouseY);
        Laya.stage.off(Laya.Event.MOUSE_MOVE, this, this.mouseMove);
    } 
    // 窗口大小改变,把地图的视口区域重设下
    private resize(): void {
        //改变地图视口大小
        this.tiledMap.changeViewPort(this.mX, this.mY, Browser.width, Browser.height);
    } 
}
已邀请:

少数人

赞同来自:

回调方法没有被执行
 

Laya_z

赞同来自:

用我们的资源和用你的代码测试结果是没有问题的,回调正常进入,地图正常加载出来了,有勾选相应类库吗(laya.tileemap.js),或者可能是你的资源有问题,建议检查一下你的资源,

要回复问题请先

商务合作
商务合作