-
Notifications
You must be signed in to change notification settings - Fork 325
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
服务端如何使用本地图片 #248
Labels
Comments
实在不支持的话,我的备选方案是datauri,尝试了一下是支持datauri的。 |
你好,读本地资源是支持的,但是需要用file协议 await scene.preload({
id: "headerSprite",
src: `file:///${path.join(process.cwd(), "images", "header.png")}`,
}); |
我想起来,你可以重写 import ENV from 'spritejs';
ENV.loadImage = function(src) {
// 这里实现从本地加载文件
} |
重写也没啥用吧,源代码也就是返回个Image,还是得src 虽然他注释里写了支持local,但是我这就是不支持呢 空了再研究一下 |
先贴一下base64的临时方案 import fs from "fs";
import mineType from "mime-types";
export default async (filePath: string) => {
const type = mineType.lookup(filePath);
var data = await fs.promises.readFile(filePath, { encoding: "base64" });
return "data:" + type + ";base64," + data;
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
如题
尝试使用path拼接路径,
fs.existsSync
检测文件是存在的,但是preload
并不能加载。是不支持,还是有其它写法?
The text was updated successfully, but these errors were encountered: