The place where random ideas get written down and lost in time.
2024-01-01 - Defold vs Godot
Category DEVWeek of 2023-12-24 to 2023-12-31, I wrote Nerdkill Defold. Worked well, was easy to use and get something.
One thing that was nice was that I ported the original game, with all the original 8 “weapons”.
Started looking at Nerdkill w/ Godot 4.2, just to compare with Defold.
Not sure there's a point in concluding that one though.
A new Asqare using Godot 4 for Android would make more sense.
One angle of Nerdkill w/ Godot would be how to create a project that can produce both a web version and a mobile version? More specifically, I’d want the screen form factor to be different.
- Nerdkill “desktop” in landscape can use the cartouche with the 8 weapons.
- Nerdkill “mobile” in portrait can use the 5 weapons.
I could of course change the mobile version to have the same 8-weapons row, but I feel the mobile version looks better that way.
(Alternate idea: consider using 7 weapons on mobile; drop the flag. 2 rows of 5 slots each, the cartouche would occupy the 3 middle bottom slots.)
So one thing I realize I don’t know if it’s possible is to configure the window size dynamically, or at least static by export type. Or maybe it could be two projects using the same resources.
https://forum.godotengine.org/t/how-to-change-window-size-using-gdscript/2861/3
“get_window().size = Vector2i(width, height)”
https://docs.godotengine.org/en/stable/tutorials/rendering/multiple_resolutions.html
“the size in Project Settings > Display > Windows… think of it as the design size”
“to support both landscape and portrait, consider using e.g. 720x720”
So in my case, I’d target these resolutions:
- Web/desktop mode: 640x480 (4:3 aspect ratio) in stretch “Viewport/Keep” mode.
- Mobile: 320x640 (18:9 aspect ratio) in stretch “Viewport/Keep” mode.
- Why this size? Comparing Pixel 5 / 3 / Samsung S24
- Pixel 5 is 1080 width with ~19:9 aspect ratio
- Pixel 3 is 1080 width with 18:9 aspect ratio
- Pixel 5 is 1440 width with ~19:9 aspect ratio
- So we go for an 18:9 ratio (double height) instead of 16:9.
- 5 weapons is 320 pixels wide (5 x 64); we rescale the cartouche to that size.
Then we can:
- Set the editor to 640x640 which is the common resolution (at least for working).
- We’ll need a flag somewhere to force the mode for testing/debugging.
- Detect the running platform using the “features” set by export https://docs.godotengine.org/en/stable/tutorials/export/feature_tags.html
- “OS.has_feature(name)”
- “android” (not in web browser, that’s “web_android” or just “web”)
- There are others but that’s all we need.
- Set the screen resolution based on the OS feature.
Since I have a “skeleton” app to play with, let’s try this out. In the same vein that I discovered that the web export in Godot 4 is… problematic, I need to try the Android export. That’s the perfect project to experiment with stuff like that.
Note on Godot 4 Web Export:
- One way to remove that “Service Worker” incompatibility issue is to use “coi-serviceworker”.
- References:
- https://github.com/gzuidhof/coi-serviceworker (what I used)
- https://www.npmjs.com/package/coi-serviceworker (as an NPM)
- https://godotengine.org/asset-library/asset/1818 (as a Godot Plugin)
- Export the coi-serviceworker.js next to the index.html.
- Modify Godot > Export > Header Include to add
<script src=\"./coi-serviceworker.js\"></script> - It’s not perfect, it seems to sometimes only work when reloading the page?
- TBD: I used the github JS directly, should try with the Godot 4 plugin instead.