-
Notifications
You must be signed in to change notification settings - Fork 7.1k
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
Loader can't load from file:// [$50] #3464
Comments
Hello, I am able to load from |
I'm having the same issue on my application that I tried to run under Cordova/PhoneGap. |
@Mikurox have you tried moving your assets in a folder relative to your |
It works when I use images in the index.html or reference them in css file. this.load.image('starfield', 'assets/images/starfield.png'); It's working when using the "browser" platform but not "android" |
Exactly what @Mikurox said. Using the built-in Phaser function The same issue is happening with Cordova apps as it seems it does not serve the files as a "server" but just accesses them through their path from the filesystem. |
Yes, the v3 loader uses xhr for all files to get per-byte download feedback, per-file. I have posted a bounty on this issue as I don't have Cordova / PhoneGap set-up, so it would take a while to debug here. |
I might be able to take a look at this, this weekend. If you provide a example where this happens I'll save some time and might be able to do it :-) |
I've tested it just in few platforms but a possible solution is to use url-loader with blobs. In your webpack.config.js Then import of your static file will return b64 string
};` and use it |
Cheers for all the feeback and ideas. Will look into this more after the weekend! @Saturate just try opening a basic Phaser 3 example directly from a folder in your browser. The error will happen as it can’t load the files through xhr. Use Chrome so you get an error message in the console. |
Not sure this helps. I haven't had a chance to try it, but there is a tutorial on line. https://gamedevacademy.org/creating-mobile-games-with-phaser-3-and-cordova/ |
Never mind, I tried the tutorial and the graphics don't show up |
Hi, @sftsk: incompatibility of Phaser 3 with direct loading through As described the solution for desktop browsers is to serve files through a server, which is a very standard practice nowadays, even for development. As for Cordova in iOS, which is OP's described situation, the above solution is more complex to implement, but it is still a known and widely used practice as well.
While @Huararanga's workaround is probably valid, a drawback is that all files are now base64 strings in your code, making it much heavier. Hope this helps. |
As I mentioned above v3 uses xhr for all files, including images. v2 used the Image tag itself to load them, however it still used xhr for all json, xml, etc. I believe under Cordova in v2 you were still able to load things like texture atlases and bitmap fonts without any issue, so xhr must have been working to some extent back then? Which makes me wonder if it's actually something else causing this. |
I have finally had time looking into this and got into the same solution as proposed by @ghybs . Installing https://github.com/ionic-team/cordova-plugin-ionic-webview with Cordova fixes the issue. This will only be a fix for iOS, although probably for Android exists something similar. I don't think there is anything to be done within Phaser as this Anyway, thanks for all the help, issue can be closed from my point of view. Perhaps add some instructions to the manual of needing the mentioned plugin when wrapping an app with Cordova. |
Hi guys, |
Just as little extra info. The demo I mentioned above works fine on android. Images/Atlas load and show properly on a galaxy s8. So this definitely appears to be a an iOS issue. |
Adding the cordova-plugin-ionic-webview as suggested by @ghybs and @sftsk worked for me. At least it started loading my json file then. For the spritesheets to show up i had to change:
to:
In the cordova index.html. Adding the Still need to add sound to my current project though. If i need to do anything special for that i'll post it here. |
Discovered this a couple of months ago. Does this help? Phaser v3.x.x (20180322); WARNING ANTI-PATTERN REMOVED |
Can't see how this makes any difference tbh. All asset loading is done via a protocol. |
I tried that plugin but it always through error in XCode when compiling "cordova-plugin-ionic-webview" so I decided to try "cordova-plugin-wkwebview-file-xhr" instead, it worked but it has weird thing about splashing the background with assets and any graphics library rect fill not working correctly (flickering). I even tried adding "cordova-plugin-wkwebview-engine" as suggested by some websites but still the same problem Attached some pics |
I was very excited to start a project that uses phaser3-typescript-webpack-cordova. Everything works perfectly until I start testing the cordova with the build package. The phaser assets loader isn't designed for loading assets from IOS. Really hope there's an official instruction of how to load assets from Cordova wrapped app. Thanks. |
These are some of the solutions I stumbled upon, hope it is helpful: |
I've just merged in a PR which should (?!) resolve this, so would be happy if someone using Cordova on iOS could build from master and test it please. |
Doesn't work, But there is a difference of behavior in iOS and Android. In iOS: |
Is there any update about this problem? |
This Issue is about a bug in the API (v3.3.0):
I have tried wrapping a Phaser app in Cordova/ React Native.
It mostly worked but there are issues with loading files. Neither
images
norjson
can be loaded, they fail without a proper error.After close debugging I noticed that the "Request Type" comes up as
XHR
whereas with Phaser 2.x it's image/ json like it should be.I have set up a very basic example
textures/sprite sheet.js
and a more complex project, both fail.Could this be related to #2670 or #2485? Did this fix get lost in 3.x?
Any help is very appreciated, did anybody manage to wrap a Phaser 3 project with Cordova?
Cheers!
p.s.: www.zip the content of www within the Cordova app
UPDATE 29.03:
I have looked into this more. It seems like the issue has to do with the Phaser 3 loader not being able loading resources from
file://
. When I open the basic texture examples from Phaser 2 without being served from a server they work just fine, the Phaser 3 ones don't. Seems the loader does something differently so CORS becomes an issue.There is a $50 open bounty on this issue. Add to the bounty at Bountysource.
The text was updated successfully, but these errors were encountered: