crystal-bit / godot-game-template Goto Github PK
View Code? Open in Web Editor NEWGeneric template for Godot games
License: MIT License
Generic template for Godot games
License: MIT License
Currently there is no way to pause the game when playing from a mobile device (native app, or HTML5 from a mobile device).
godot-game-template/addons/game-template/scenes.gd
Lines 54 to 63 in d094a33
Issue: a new scene can start before old nodes to be completely removed.
I noticed this reloading a scene which had get_tree().get_nodes_in_group("example_group")
on ready: I was expecting 3 nodes, but I got 6. This happened because old nodes were not completely removed on reload.
ggt-*
addonIdea:
After pre_start
, but before start
the scene can add more "in-scene" stages to the progress-bar.
I think the pre_start function can be used for this, and maybe using yield
to advance the progress bar (coroutines style) or by emitting signals.
I guess that in order to have proper progress-bar the number of "in-scene" stages need to be known before the scene is loaded, which is tricky, a simple solution is to pass it in the params, but I hope there is a more elegant solution.
Example use case:
The gameplay.tscn scene generates procedural level in the pre_start func
func start_button_pressed():
Game.change_scene("res://gameplay.tscn",
{ "show_progress_bar": true,
"in_scene_stages": 5 # tell the progess bar to reserve 5 extra stages
})
# in gameplay.gd
func pre_start(params):
generate_maze()
yield() # advance stage... or use signal and wait for idle frame?
generate_tiles()
yield()
generate_treasure()
yield()
generate_monsters()
yield()
generate_doors()
func start():
play_start_game_sound()
func reparent_node(node: Node2D, new_parent, update_transform = true):
var previous_xform = node.global_transform
node.get_parent().remove_child(node)
new_parent.add_child(node)
node.global_transform = previous_xform
This is not implemented in Godot because it's easy to do with GDScript.
However it seems like a handy feature to have in a game template (and also to avoid duplicating code).
Relevant Godot issues:
var size := Vector2.ZERO
func _ready() -> void:
get_tree().connect("screen_resized", self, "_ on_screen_resized")
register_size()
func _on_screen_resized():
register_size()
func register_size():
size = get_viewport().get_visible_rect().size
Invalid set index 'initial_fade_active' (on base: 'Node (main.gd)') with value of type 'bool'.
See 26b097d
This behaviour could be annoying for many people that rely on default Node events.
Add signals:
Even when the scene transitions completes, the Transitions scene remains in the tree, but it is invisible (since ColorRect is animated to be alpha=0).
However, it still blocks _input events.
ie. if there is a button where the progress bar is located, it is impossible to click the button (or hover it), even when the progress bar is invisible.
The fix is simple, and I think as a bonus side affect it will probably (very slightly) improve performance (perhaps avoiding some needless process() and rendering of transparent textures).
Simply hide
the ColorRect when its not needed:
transitions.gd (modified lines highlighted with <<<<<<<
, unchanged functions omitted for brevity)
onready var background = $ColorRect
func _ready():
background.hide() # <<<<<<<
# Tells if transition is currently displayed
func is_displayed() -> bool:
return background.visible # <<<<<<<<
#
# I don't think these two lines are necessary, but maybe I'm missing something?
# var is_screen_black = background.modulate.a == 1
# return anim.is_playing() or is_screen_black
# appear
func fade_in(params = {}):
background.show() # <<<<<<<<
progress.hide()
if params and params.get('show_progress_bar') != null:
if params.get('show_progress_bar') == true:
progress.show()
anim.play("transition-in")
func _on_fade_out_finished(cur_anim):
if cur_anim == "transition-out":
progress.bar.value = 0
background.hide() # <<<<<<<<<
# rest of file is unchanged
See 9aa7076
set_enabled_focus_mode: BaseButton's Enabled Focus Mode property has been deprecated due to redundancy and will be removed in Godot 4.0. Please use Control.set_focus_mode instead.
<C++ Error> This method has been deprecated and will be removed in the future.
<C++ Source> scene/gui/base_button.cpp:329 @ set_enabled_focus_mode()
<Stack Trace> scenes.gd:57 @ _set_new_scene()
scenes.gd:118 @ _on_resource_loaded()
resource_interactive_loader.gd:51 @ _on_background_loading_completed()
resource_interactive_loader.gd:30 @ _process()
After merging #37 I started wondering if a debug HUD may be useful for end users.
In https://github.com/crystal-bit/godot-game-template/tree/feature/version-scene there is a proof of concept: a Godot scene which is enabled globally and can be shown/hidden by pressing F1
at any moment (even during transitions).
Do you think having the godot-game-template should ship a debug HUD by default? Or should it be an add-on to install optionally?
Keep in mind that this debug HUD should work on PC, HTML5, Android and iOS. If this is hard to achieve, then I think it's better to create a separate add-on (which could be installed by other Godot-projects as well).
PS: for inspiration I suggest reading the Addons & Plugins wiki page and especially Shovel Knights debug features. If you know about similar resources, feel free to post them!
After I've created a repo from this template, the Build Action for Web is failing with error:
remote: Permission to jayypluss/BreezyWave.git denied to github-actions[bot].
fatal: unable to access 'https://github.com/jayypluss/BreezyWave.git/': The requested URL returned error: 403
Is there any action needed for this build action to work?
Link for the failing build line:
https://github.com/jayypluss/BreezyWave/runs/6251779089?check_suite_focus=true#step:9:99
Thanks!
Would it be possible to port the template in godot 4? I use godot 4 and i'd like to be able to use the template too!
I plan to support Godot 4.0 when it will be released.
There will be many changes, these things need to be kept in mind:
It needs to be optimized: the while loop can be removed
# Normalize EOL for all files that Git considers text files.
* text=auto eol=lf
See:
Add an option to Project Settings
As reported in #54 (comment), users can't pause the game in _ready()
.
This behaviour is probably a bug due to:
# main.gd
func _on_Scenes_change_finished():
get_tree().paused = false
https://github.com/crystal-bit/godot-game-template/blob/main/scenes/main/main.gd#L100-L101
Right now the multithread Scene manager waits for the graphic transition end before starting loading the new resources, wasting time. This can be improved to have faster loading times.
https://github.com/crystal-bit/godot-game-template/blob/main/autoload/scenes.gd#L156
I think it would be useful to have the current version of the project shown on the bottom-left of the main scene. If people experience a bug with the template or a game made with it, they could immediately check which version is running, and it would be easy for non-developers as well.
Godot 3.2.3 HTML5 export does not support threads; https://docs.godotengine.org/en/stable/getting_started/workflow/export/exporting_for_web.html#unimplemented-functionality
Godot 3.2.4 will have HTML5 export templates with support for threads: https://godotengine.org/article/dev-snapshot-godot-3-2-4-beta-4
TODO:
Use cases:
Fancy Fades has a bunch of scene change animations - see https://godotengine.org/asset-library/asset/741
It would be great to have it integrated with Godot Game Template
From Godot Third Person Shooter demo:
if ResourceLoader.has_cached(path):
emit_signal("replace_main_scene", ResourceLoader.load(path))
else:
res_loader = ResourceLoader.load_interactive(path)
loading_thread = Thread.new()
#warning-ignore:return_value_discarded
loading_thread.start(self, "interactive_load", res_loader)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.