Wednesday, 24 October 2018

10 Tips For Using The Godot Engine

Fuck me I really am doing a top ten list aren't I? Jesus Christ. Anyway, let's get to it, I guess let's start with number one.

1. Singletons. These are basically scripts that don't really attach themselves to any existing node, which means that they exist outside of the current scene- which makes them perfect for things like saving data, playing music uninterrupted between scenes or preloading a bunch of resources to be used later. I've got 14 singletons in WARP-TEK as we speak, so I can tell you that I really like using them.

2. PhysicsBodies. This is close enough to a tip, right? Let me just run through the three types of 2D PhysicsBody nodes and their usual use-case.

KinematicBody2D nodes are what I use for most things that need to move around, so enemies, the player, other colliding entities, etc. RigidBody2D nodes are good for physics-based movement, so if you wanted some boxes for a puzzle game that move and fall like real boxes would, then you'd want to use RigidBody2D. Or, you COULD use KinematicBody2D but you'd have to program all the physics stuff yourself.

Lastly, StaticBody2Ds are good for anything that should never move like walls or the floor. Easy enough but it's good to know the difference.

3. The ternary operator. Now most programming languages have this one, it's the question mark one in C++ and in Python it's just thing if condition else other_thing. In GDScript, it's the same as in Python(as most things tend to be) and it's super useful. I realize it's much nicer to use this ternary operator on one line rather than dedicating 4 lines to an if/else block.

4. Here's a more functional tip, and it's based off something I actually do in WARP-TEK. Use a Singleton script to preload all of your resources to speed up in-game performance. This way if you want to instance a node, you just refer to its entry in this monolithic resource script and instance it. It has in my experience with preloading over a hundred objects made the game start up maybe half a second slower, but it drastically reduces lag-spikes that stem from repeatedly having to load or preload resources, such as when you're spawning a big blast of 30 or 40 bullets.

5. Specifying neighbours in Control nodes. So have you ever run into the issue where you want a menu to be usable with the arrow keys or a D-pad but Godot just won't direct to the correct buttons in the proper order? Well, I haven't because I haven't really considered keyboard accessibility until really recently but there is a really neat solution to this problem.

Any control node will have the "Focus" category, and you can see there are a few properties like "Neighbour Left", "Neighbour Down", etc which basically determine what happens when this button is focused and a specific key is pressed. In case this explanation wasn't super clear I'd say just play around with it because it's a really simple concept and it's implemented really well.

6. NinePatchRects. This is also related to a Control node, but trust me- this is super useful, and it's actually a new thing that only just appeared in Godot 3. Basically, for Mass O' Kyzt I had to manually size and align all the edges and corners for all the menu panels and stuff. For WARP-TEK, I've specified a 3x3 grid of what each corner, edge and middle piece should look like, loaded it into a NinePatchRect and all you have to do is resize it and it'll automatically scale or tile the corresponding parts of the graphic to fit a size of your choosing.

It's super convenient and while it sometimes takes a moment or two to actually configure it so it scales how you want it to, it's definitely worth looking into.

7. Have you ever had that issue where you're cooking pasta for a while and you stir it but you're kind of impatient and you think "well, this is probably good enough" and you strain it and put it into a bowl and you take a bite and it's really crunchy in the middle and so you put it back into water but you have to heat up the water because you used cold water but by the time the pasta's boiling again the pasta has actually dissolved into the water and you're left with a kind of starchy gloop that you have to turn into a soup but you don't even really like soup so you just pour it out and then it blocks the drain because it's still really thick in places and then your sink overflows and instead of calling a plumber or even turning off the hot water tap you just sit under the table crying and feeling malaiseful about your terribly out-of-control life while you wait for the small puddle of water on the kitchen floor to reach you and force you to either clean it up or deal with soggy clothes but when it does actually reach you you just realize you don't have the energy or motivation to even get up off the floor for another hour and your clothes get completely saturated in warm starchy water and by the time you do get around to cleaning it up you've done permanent water damage to that stack of important envelopes that you've been meaning to pick up off the floor but never got around to?

...No? Alright then, moving on.

8. Autotiling! Of course this one had to be on the list. It's a little tricky to get your head around initially what with the bitmask stuff but it's super useful once you do get the hang of it. I won't try to explain it too much here but trust me- learn it. It'll take you an afternoon at the absolute longest, and potentially even faster if you watch my tutorial video on autotiling (I think I have one, I suppose I should check before publishing this but fuck you I guess)

9. Using an external code editor! I did do this for about a day with Sublime Text before realizing that Godot's built-in code editor is fine for my needs but if I had a strong preference(for instance, if I was a Vim or Emacs fanatic) then I would be in luck, because Godot makes it super easy to use a third party editor. Just go to Editor in the top left, Editor Settings, and under "Text Editor" click "External" and configure to your heart's content.

10. The new Audio Bus system. Okay, I don't think this really counts as a tip but it's just something I really like about the engine and you gotta agree it's a step above whatever the fuck 7 was about. Basically, I generally create two new buses in addition to the master bus, and I call them "music" and "sound". Fairly self-explanatory, but the idea is that you route all the music sound through the music bus and all the sound effects through the sound bus. If you wanted to you could have buses for ambient sounds, voice, etc.

The point is that this makes things easier for you when you're adjusting system volume. You can make a nice volume slider that directly adjusts the volume of the music bus, and another that corresponds to the sound bus. This stops you from having to save another variable like music_volume and refer to it any time you want to play some music.

Anyway, that's about all I've got. If you have any more interesting things about the engine that you think I and the world should know about, for real let me know in the comments- I'm still learning new things about the engine constantly!

Thanks for watching, and stay tuned for more top ten lists... maybe... probably not though because this was a pain and really long to write sooo.. uh.. goodbye.

No comments :

Post a Comment