提示コードですが参考サイトように画像を読み込んだのですがエラーになります。これはなぜでしょうか?調べたところによるとJavaScriptが外部のデータをはじいている?みたいのですがどうすれば外部のデータを読み込めるのでしょうか?
ライブラリ: p5
参考サイト: https://editor.p5js.org/LukeGarrigan/sketches/WS_5sauc2
リファレンス: https://p5js.org/reference/#/p5/loadImage
console
p5.js:80673 Fetch API cannot load file:///C:/Users/○○/Desktop/js/Space_Invaders/Asset/enemy.png. URL scheme "file" is not supported. _main.default.loadImage @ p5.js:80673 (anonymous) @ p5.js:62949 preload @ Game.js:6 _start @ p5.js:62905 p5 @ p5.js:63261 _globalInit @ p5.js:62189 Promise.then (async) 280.../core/main @ p5.js:62214 o @ p5.js:34 (anonymous) @ p5.js:38 267../accessibility/color_namer @ p5.js:54831 o @ p5.js:34 r @ p5.js:51 (anonymous) @ p5.js:55 (anonymous) @ p5.js:18 (anonymous) @ p5.js:20 p5.js:59792 🌸 p5.js says: It looks like there was a problem loading your image. Try checking if the file path (Asset/enemy.png) is correct, hosting the file online, or running a local server. (More info at https://github.com/processing/p5.js/wiki/Local-server) p5.js:80750 TypeError: Failed to fetch at p5._main.default.loadImage (p5.js:80673:13) at p5.js:62949:67 at preload (Game.js:6:16) at p5._start (p5.js:62905:27) at new p5 (p5.js:63261:22) at _globalInit (p5.js:62189:17) (anonymous) @ p5.js:80750 Promise.catch (async) _main.default.loadImage @ p5.js:80745 (anonymous) @ p5.js:62949 preload @ Game.js:6 _start @ p5.js:62905 p5 @ p5.js:63261 _globalInit @ p5.js:62189 Promise.then (async) 280.../core/main @ p5.js:62214 o @ p5.js:34 (anonymous) @ p5.js:38 267../accessibility/color_namer @ p5.js:54831 o @ p5.js:34 r @ p5.js:51 (anonymous) @ p5.js:55 (anonymous) @ p5.js:18 (anonymous) @ p5.js:20
Game.js
"use strict" let sprite; function preload() { sprite = loadImage('Asset/enemy.png'); } class Stage { constructor() { this. enemyArray [ [], [], [] ]; } } class Player { constructor() { } } class Game { constructor() { } Update() { } Renderer() { image(sprite,10,10,10,10); } }
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。