我按照官网文档,使用 resources.load 方法动态的调用assets/resources里的资源,官方文档是这么写的,然后我按照官方文档只用该方法调用相应的资源,在运行的时候,都会出现目标资源找不到的错误,这是什么原因?后来我问了很多人,只给我的一个资源的加载解决办法,是sprite 在动态加载纹理的时候,“images/bg1/spriteFrame” 路径要这么写,resources.load加载才能成功,其他的资源类型就不知道了,比如 prefab,音频文件,这些资源按照官方文档写出来都是报错的,请问是怎么回事呢?顺便,我个人贴一下我调用 prefab的方法,请各位大佬给看一下 enum ResourcesPath {
GroundPrefab = “Prefabs/Ground/BackGround”,
},
resources.load(ResourcesPath.GroundPrefab,Prefab,(error:Error,prefab: Prefab)=>{
if (error){
console.error('Load image failed:', error);
return
}
this._ground = instantiate(prefab);
this._baseNode.addChild(this._ground);
this._ground.setPosition(new Vec3(this._initVec2.x, this._initVec2.y, 0));
this._ground.setScale(new Vec3(1,1,1));
this._sprite = this._ground.getComponent(Sprite);
this._uiTransForm = this._ground.getComponent(UITransform);
if (this._uiTransForm && this._sizeData) {
this._uiTransForm.setContentSize(this._sizeData.x, this._sizeData.y);
}
}); 这段代码进行调试的时候,就会报刚才所说的错误。
