Hello aspiring game devs! As you know from my previous post I've been getting into Godot, and I'm pretty excited.
As I follow this course on Udemy, after every tutorial I try to make a game. I always make a game that's harder than what I just worked on. This way, I get to practice what I learn but I'm also forced to learn new things without a guided hand. While painful, it deepens my understanding of what's going on.
Since my last project, here are some technical bits I've picked up on that I'll carry with me for future projects.
In all development languages/frameworks, structure is a matter of personal taste and project size. For very small games or quick prototypes, you can get by with a flat structure. The one I've settled with for my small projects is:
In whatever way it's done, the majority of the community prefers to separate the scenes from the scripts. Some larger games also have hierarchies in their
scripts folders as the need arises.
This is nothing big but it's something I'll probably forget. If you want to check if a node exists in a scene, use this code snippet:
But to check if a node has a property, like one you'll edit in the GUI, simply do this:
A YouTube video I can't find anymore :-( showed me this awesome technique for making menu buttons. After creating a basic menu button scene, attach this script to it:
We add two variables that can be configured in the GUI for menu buttons. The
scene_to_load takes a resource path of which scene the menu button should load when it's clicked. The
quit_game flag tells us if this button is being used to quit the game.
Then, attach a script similar to this for your menu scene:
In the ready function, we do two things: highlight the first menu button that's added to the scene and connect the
pressed event of the menu buttons to our
_on_Button_pressed function. Using the for loop allows us to use one function to handle button presses for all the menu options.
_on_Button_pressed function checks if a button is being used to quit the game, and handles that separately. For all other buttons, store what scene it was meant to load and play a fade animation.
Once the animation is complete, we'll switch to that scene stored in
scene_path_to_load. This very simple setup makes scene switching in menus a breeze
Happy game developing!