我调用cc.loader.load加载原生的本地图片资源,
如果图片存在,load方法能正确回调completeCallback
如果图片不存在,不会回调completeCallback
从log日志中看到这样的错误日志:
E/jswrapper: [ERROR] (D:/CocosCreator/resources/cocos2d-x/cocos/scripting/js-bindings/manual/jsb_global.cpp, 786): initWithImageFile: /storage/emulated/0/DiscoverLand/10/gameRes/gameName.png failed!
我的逻辑需要在出现错误时,我在completeCallback回调中执行出错的逻辑,但现在是不能的。
下面是我的逻辑代码,图片不存在时,
回调中的console.log(“setImageRes 换肤 filePath:” + filePath + “,err:”+err)日志是没有打印出来的。
function(sprite,imageName,callback){
let filePath = nativeGameResDir + imageName+".png";
console.log(“setImageRes 换肤 filePath:” + filePath);
cc.loader.load(filePath, function (err, texture) {
console.log(“setImageRes 换肤 filePath:” + filePath + “,err:”+err);
if(typeof err == “undefined” || err == null || err == “” ){
sprite.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture);
} else if(callback != null){
callback(err,sprite,imageName);
}
});
}
请大家帮忙看一下是我代码的问题,还是creator的BUG。以及怎样解决

