bundle.loadScene 加载场景的时候如果回调函数写在外面就不会调用,这是个bug吗?

如果这样写,加载完成后loadSceneComplete函数是不会调用的
onLoad() {

    cc.assetManager.loadBundle("MainBundle", function (err: Error, bundle: cc.AssetManager.Bundle): void {

    bundle.loadScene("Main", this.loadSceneComplete);

    });

}

private loadSceneComplete(err: Error, sceneAsset: cc.SceneAsset): void {

    cc.log("Load Scene Completed"); //这个函数里这两句是不会调用的

    cc.director.runScene(sceneAsset);

}

如果像下面这样用箭头函数写就没问题
bundle.loadScene(“Main”, (err: Error, sceneAsset: cc.SceneAsset) => {
cc.log(“Load Scene Completed”);//这样写就没问题,这里都能调用
cc.director.runScene(sceneAsset);
});

不知道这是什么原因,是不是一个bug呢?creator版本用的是2.4.10

你在loadBundle的回调里,打印一下this就明白了

可以改成下面这样就好了

cc.assetManager.loadBundle(“MainBundle”, (err: Error, bundle: cc.AssetManager.Bundle)=> {

bundle.loadScene("Main", this.loadSceneComplete);

});

哈哈哈,脑子可能被阳坏了,我自己犯了低级错误,是this的指向问题,谢谢