key_concepts_overview.rst 3.9 KB

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