key_concepts_overview.rst 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. .. Intention: introduce only a handful of key concepts and avoid a big cognitive
  2. load. Readers will then be reminded of the concepts further in the getting
  3. started series, reinforcing their learning.
  4. .. _doc_key_concepts_overview:
  5. Overview of Godot's key concepts
  6. ================================
  7. Every game engine revolves around abstractions you use to build your
  8. applications. In Godot, a game is a **tree** of **nodes** that you group
  9. together into **scenes**. You can then wire these nodes so they can communicate
  10. using **signals**.
  11. These are the four concepts you will learn here. We're going to look at them
  12. briefly to give you a sense of how the engine works. In the getting started
  13. series, you will get to use them in practice.
  14. Scenes
  15. ------
  16. In Godot, you break down your game in reusable scenes. A scene can be a character,
  17. a weapon, a menu in the user interface, a single house, an entire level, or
  18. anything you can think of. Godot's scenes are flexible; they fill the role of
  19. both prefabs and scenes in some other game engines.
  20. .. image:: img/key_concepts_main_menu.webp
  21. You can also nest scenes. For example, you can put your character in a level,
  22. and drag and drop a scene as a child of it.
  23. .. image:: img/key_concepts_scene_example.webp
  24. Nodes
  25. -----
  26. A scene is composed of one or more **nodes**. Nodes are your game's smallest
  27. building blocks that you arrange into trees. Here's an example of a character's
  28. nodes.
  29. .. image:: img/key_concepts_character_nodes.webp
  30. It is made of a ``CharacterBody2D`` node named "Player", a ``Camera2D``, a
  31. ``Sprite2D``, and a ``CollisionShape2D``.
  32. .. note:: The node names end with "2D" because this is a 2D scene. Their 3D
  33. counterparts have names that end with "3D". Be aware that "Spatial"
  34. Nodes are now called "Node3D" starting with Godot 4.
  35. Notice how nodes and scenes look the same in the editor. When you save a tree of
  36. nodes as a scene, it then shows as a single node, with its internal structure
  37. hidden in the editor.
  38. Godot provides an extensive library of base node types you can combine and
  39. extend to build more powerful ones. 2D, 3D, or user interface, you will do most
  40. things with these nodes.
  41. .. image:: img/key_concepts_node_menu.webp
  42. The scene tree
  43. --------------
  44. All your game's scenes come together in the **scene tree**, literally a tree of
  45. scenes. And as scenes are trees of nodes, the scene tree also is a tree of
  46. nodes. But it's easier to think of your game in terms of scenes as they can
  47. represent characters, weapons, doors, or your user interface.
  48. .. image:: img/key_concepts_scene_tree.webp
  49. .. _doc_key_concepts_signals:
  50. Signals
  51. -------
  52. Nodes emit signals when some event occurs. This feature allows you to make
  53. nodes communicate without hard-wiring them in code. It gives you a lot of
  54. flexibility in how you structure your scenes.
  55. .. image:: img/key_concepts_signals.webp
  56. .. note:: Signals are Godot's version of the *observer* pattern. You can read
  57. more about it here:
  58. https://gameprogrammingpatterns.com/observer.html
  59. For example, buttons emit a signal when pressed. You can connect to this signal
  60. to run code in reaction to this event, like starting the game or opening a menu.
  61. Other built-in signals can tell you when two objects collided, when a character
  62. or monster entered a given area, and much more. You can also define new signals
  63. tailored to your game.
  64. Summary
  65. -------
  66. Nodes, scenes, the scene tree, and signals are four core concepts in Godot that
  67. you will manipulate all the time.
  68. Nodes are your game's smallest building blocks. You combine them to create scenes
  69. that you then combine and nest into the scene tree. You can then use signals to
  70. make nodes react to events in other nodes or different scene tree branches.
  71. After this short breakdown, you probably have many questions. Bear with us as
  72. you will get many answers throughout the getting started series.