sachu Posted April 24, 2019 Share Posted April 24, 2019 I'm trying to add sprites from a sprite sheet but the assets won't load. I've attached my code and the console logs below that show the error. I've also attached the file to show that my file location seems to be correct. I'm not sure what the issue is any help would be greatly appreciated. Link to comment Share on other sites More sharing options...
mattstyles Posted April 26, 2019 Share Posted April 26, 2019 The issue is your bundler. When you add non-standard things to your 'regular' JS, you can't expect perfect interoperability with JS libraries (such as Phaser) which expect you to write in JS. The issue lies with however your bundler transforms `./assets/button.png`, usually, this will become a file path, which would work fine if, and only if, the paths are correct. I am going to guess that in your case, they are not correct, hence the 404. More strangely, it doesn't even try to insert a path, just the variable name, which either means you're calling Phaser functions wrong, or, the bundler is really mucking you around. Most bundlers that allow you to import asset paths also will handle packing those assets and they _should_ also handle serving it for you in the same way they're serving your HTML and other static code assets. sachu 1 Link to comment Share on other sites More sharing options...
sachu Posted April 26, 2019 Author Share Posted April 26, 2019 Ended up starting from scratch with a whole new local server service and for some reason, it works (exact same code). I was using NodeJS so I'm assuming I must have messed up the setup process at some point Link to comment Share on other sites More sharing options...
mattstyles Posted April 27, 2019 Share Posted April 27, 2019 Nah, it probably wasn't you, its the path serving, it can go a bit screwy (depending on the bundler) when you import straight in to your code like that. There can also be a difference (again, depending on the bundler setup) between prod and dev builds. It all depends how they handle asset loading. sachu 1 Link to comment Share on other sites More sharing options...
Recommended Posts