const img = path.join(__dirname, `./assets/imgs/trans/一0${index}.jpeg`);
  const bg = new FFImage({path: img, resetXY: true});
  scene.addChild(bg);

  // title text
  const ftext = new FFText({text, x: width / 2, y: height / 2 + 50, fontSize: 38});
  ftext.setColor('#30336b');
  ftext.alignCenter();
  ftext.setBackgroundColor('#ffffff');
  ftext.addEffect('fadeInRight', 1, 1.3);
  ftext.setStyle({padding: [4, 12, 6, 12]});
  scene.addChild(ftext);

报错

(node:9836) ExperimentalWarning: The fs.promises API is experimental
(node:9836) UnhandledPromiseRejectionWarning: Error: ENOENT, No such file or directory 'C:\Users\asus\FFCreator\examples\assets\imgs\trans\一01.jpeg'
    at setSource (C:\Users\asus\FFCreator\node_modules\canvas\lib\image.js:91:13)
    at Image.set (C:\Users\asus\FFCreator\node_modules\canvas\lib\image.js:62:9)
    at Promise (C:\Users\asus\FFCreator\node_modules\canvas\index.js:34:15)
    at new Promise (<anonymous>)
    at loadImage (C:\Users\asus\FFCreator\node_modules\canvas\index.js:23:10)
    at Object.ENV.loadImage (C:\Users\asus\FFCreator\node_modules\spritejs\lib\platform\node-canvas.js:38:43)
    at loadTexture (C:\Users\asus\FFCreator\node_modules\spritejs\dist\spritejs.js:28552:63)
    at _callee$ (C:\Users\asus\FFCreator\node_modules\spritejs\dist\spritejs.js:28573:30)
    at tryCatch (C:\Users\asus\FFCreator\node_modules\spritejs\dist\spritejs.js:10088:40)
    at Generator.invoke [as _invoke] (C:\Users\asus\FFCreator\node_modules\spritejs\dist\spritejs.js:10318:22)
(node:9836) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 6)
(node:9836) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:9836) UnhandledPromiseRejectionWarning: Error: ENOENT, No such file or directory 'C:\Users\asus\FFCreator\examples\assets\imgs\trans\一01.jpeg'
    at setSource (C:\Users\asus\FFCreator\node_modules\canvas\lib\image.js:91:13)
    at Image.set (C:\Users\asus\FFCreator\node_modules\canvas\lib\image.js:62:9)
    at Promise (C:\Users\asus\FFCreator\node_modules\canvas\index.js:34:15)
    at new Promise (<anonymous>)
    at loadImage (C:\Users\asus\FFCreator\node_modules\canvas\index.js:23:10)
    at Object.ENV.loadImage (C:\Users\asus\FFCreator\node_modules\spritejs\lib\platform\node-canvas.js:38:43)
    at loadTexture (C:\Users\asus\FFCreator\node_modules\spritejs\dist\spritejs.js:28552:63)
    at _callee$ (C:\Users\asus\FFCreator\node_modules\spritejs\dist\spritejs.js:28573:30)
    at tryCatch (C:\Users\asus\FFCreator\node_modules\spritejs\dist\spritejs.js:10088:40)
    at Generator.invoke [as _invoke] (C:\Users\asus\FFCreator\node_modules\spritejs\dist\spritejs.js:10318:22)
(node:9836) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 7)
(node:9836) UnhandledPromiseRejectionWarning: Error: ENOENT, No such file or directory 'C:\Users\asus\FFCreator\examples\assets\imgs\trans\一02.jpeg'
发布于 2020-11-21 12:36
共1个回答
AD
游客AdtNgf

这是因为C++的fopen不能打开含有中文路径的文件(参见:https://github.com/Automattic/node-canvas/blob/master/src/Image.cc)。

所以建议您使用英文路径,如果你确实想用中文,那么需要使用iconv将文件路径转换成GBK编码。

回答问题