godotengine / godot-demo-projects

Demonstration and Template Projects
https://godotengine.org
MIT License
5.48k stars 1.53k forks source link

Correct font setup in Dodge The Creeps 2D. #1026

Closed chrisl8 closed 3 months ago

chrisl8 commented 3 months ago

The fonts were not working in Dodge The Creeps 2D example and there was an error being generated.

This fixes the issue based on how the tutorial explains to set up fronts now https://docs.godotengine.org/en/latest/getting_started/first_2d_game/06.heads_up_display.html#

I believe the Xolonium-Regular.tres file was causing this error:

Class 'Font' or its base class cannot be instantiated.
  editor/plugins/editor_preview_plugins.cpp:828 - Condition "sampled_font.is_null()" is true. Returning: Ref<Texture2D>()

Which appears in both Godot 4.2 and 4.3, although not as readily in 4.2.

The file does not seem to be necessary so I removed it.

chrisl8 commented 3 months ago

There are is one other demo projects that have has this same issue. It is less clear to me on those demos what fonts are supposed to be used where. It seems like at some point in the past the font settings were lost.:

godot-demo-projects\2d\finite_state_machine

If this is a correct solution, then I will go ahead and make a PR for godot-demo-projects\2d\finite_state_machine as well.

Also, I can bundle all of those into one PR or do them one demo at a time. Either way is fine with me.

chrisl8 commented 3 months ago

It looks like this might be the point where many demos godot-demo-projects\2d\finite_state_machine lost its fonts, and I can use this to figure out which fonts to put back:

https://github.com/godotengine/godot-demo-projects/commit/1d5184e23510ffcbbd95cab6c43b5073d1dc6eae

Does that sound right?

Calinou commented 3 months ago

Font handling was remade from scratch for Godot 4.0, so you'll need to disregard the existing .tres font resources.

Depending on your needs, there are 2 approaches:

chrisl8 commented 3 months ago

Ok, well I think this matches with the current tutorial at https://docs.godotengine.org/en/latest/getting_started/first_2d_game/06.heads_up_display.html# so it seems like the correct fix to me. It makes the fonts actually work and clears out some errors on every startup of this demo with Godot 4+