waliente / phaser-typescript-electron

A starter template that uses Phaser 3, TypeScript, Electron and Rollup and Vite for bundling.
MIT License
33 stars 6 forks source link

Fonts not carrying over to electron build correctly. #2

Open Dan-Mizu opened 1 year ago

Dan-Mizu commented 1 year ago

When testing using the browser, everything works 100%.

When trying to preview with electron, however, I get a GET file:///C:/assets/Pix.b727d010.woff2 net::ERR_FILE_NOT_FOUND error. Can't seem to see the font file within the assets directory in Sources either.

I have the font file itself under the assets/site/font directory. I load it within the index.html file and tried using WebFontLoader to try and load it with js and it still has a similar issue- where it can't find the font file. Stuff like phaser sprites and assets work fine, but not stuff included within the index.html file.

Dan-Mizu commented 1 year ago

Might have been an issue with the way I edited the main.js file. When i revert it and then run the preview it works fine (on localhost i presume) but when i build it and then try to run it, the entire screen is white and it remains in dev mode but no errors in console and nothing in sources. How are we meant to build the app/use the environment variables? That is probably the actual issue I am having.

waliente commented 1 year ago

I'll check as soon as possible.

Dan-Mizu commented 1 year ago

By the way, my repo with this issue is public here: https://github.com/Dan-Mizu/Froguelike

You can see the issue when you try use the preview command vs the dev command. I use vscode's launch.json to run each command within the run and debug tab.

saintflow47 commented 1 year ago

Hi there, did this ever get resolved? Thanks!

waliente commented 1 year ago

Hi, unfortunately this months for me are too much busy with works. If anyone can find a solution feel free to fix it ;)

Dan-Mizu commented 1 year ago

I resolved it somehow in my project but forgot how to be honest.

Here is my main.js file though if you want to compare: https://github.com/Nostalgi-cc/Froguelike/blob/update/electron/main.js

waliente commented 1 year ago

Hi can you try to share with me how can you fixed it? If you can maybe i can fix the repository and also update it to phaser 3.60

Dan-Mizu commented 1 year ago

https://github.com/Nostalgi-cc/Froguelike/commit/d48332087f90e10c7ffa3e4186705ccdaa6995b7

This commit seems to be when i fixed it.

Using WebFontLoader by Google I load the font in during my load scene from a separate css file (not within the index html file).

So really it wasn't a fix as it didn't involve changing any electron files but rather a workaround (or maybe intended?).

You should update to Phaser 3.60 but also look into updating Vite to the newest version, as that's what I did without issues.

waliente commented 1 year ago

I'll try to fix it in the master repo. And you see the font correctly also in the electron build?

waliente commented 1 year ago

Currently i've added webfontloader on "client" and works correctly, i've edit the copy-from-client.js script for create correctly the index.html in "electron", but electron actually gives me this following issue: Class WebSwapCGLLayer is implemented in both /System/Library/Frameworks/WebKit.framework/Versions/A/Frameworks/WebCore.framework/Versions/A/Frameworks/libANGLE-shared.dylib (0x7ffb546e8378) and /Users/mchierchia/Desktop/PROJECTS/Github/phaser-typescript-electron/electron/node_modules/electron/dist/Electron.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Libraries/libGLESv2.dylib (0x107b68328). One of the two will be used. Which one is undefined.

Seems is known on electron github as bug...