老项目从2.1.3升级2.4。
升级文档提示 “需要手动升级 你在自己的代码中使用了 cc.url 开头的 API,比如 cc.url.raw”,但没写如何升级。
游戏运行时提醒:
‘cc.url.raw’ is deprecated, please use ‘cc.resources.load’ instead.
但是我只想找到一个资源在项目里的真实路径,然后提供给绘图API使用,并不是想加载它,这我该如何处理呢。
老项目从2.1.3升级2.4。
升级文档提示 “需要手动升级 你在自己的代码中使用了 cc.url 开头的 API,比如 cc.url.raw”,但没写如何升级。
游戏运行时提醒:
‘cc.url.raw’ is deprecated, please use ‘cc.resources.load’ instead.
但是我只想找到一个资源在项目里的真实路径,然后提供给绘图API使用,并不是想加载它,这我该如何处理呢。
换一个引擎
我的兩種解法是這樣
// 載入編譯後檔案路徑
const url = `resources/sound/aaa.mp3`;
const changeExtname = cc.path.changeExtname(url.substr(10));
// 1
cc.resources.load(changeExtname, (error, asset) => {
if (error) {
console.error(error.message);
} else {
console.log(`nativeUrl: ${asset.nativeUrl}`);
}
});
// 2
const extname = cc.path.extname(url);
const bundle = cc.AssetManager.BuiltinBundleName.RESOURCES;
const filePath = cc.AssetManager.prototype._transform({ path: changeExtname, bundle: bundle, __isNative__: true, ext: extname });