key_concepts_overview.rst 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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.png
  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.png
  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.png
  30. It is made of a ``KinematicBody2D`` node named "Character", a ``Sprite``, a
  31. ``Camera2D``, and a ``CollisionShape2D``.
  32. .. note:: The node names end with "2D" because this is a 2D scene. Their 3D
  33. counterpart have names that end with "3D".
  34. Notice how nodes and scenes look the same in the editor. When you save a tree of
  35. nodes as a scene, it then shows as a single node, with its internal structure
  36. hidden in the editor.
  37. Godot provides an extensive library of base node types you can combine and
  38. extend to build more powerful ones. 2D, 3D, or user interface, you will do most
  39. things with these nodes.
  40. .. image:: img/key_concepts_node_menu.png
  41. The scene tree
  42. --------------
  43. All your game's scenes come together in the **scene tree**, literally a tree of
  44. scenes. And as scenes are trees of nodes, the scene tree also is a tree of
  45. nodes. But it's easier to think of your game in terms of scenes as they can
  46. represent characters, weapons, doors, or your user interface.
  47. .. image:: img/key_concepts_scene_tree.png
  48. Signals
  49. -------
  50. Nodes emit signals when some event occurs. This feature allows you to make
  51. nodes communicate without hard-wiring them in code. It gives you a lot of
  52. flexibility in how you structure your scenes.
  53. .. image:: img/key_concepts_signals.png
  54. .. note:: Signals are Godot's version of the *observer* pattern. You can read
  55. more about it here:
  56. https://gameprogrammingpatterns.com/observer.html
  57. For example, buttons emit a signal when pressed. You can connect to this signal
  58. to run code in reaction to this event, like starting the game or opening a menu.
  59. Other built-in signals can tell you when two objects collided, when a character
  60. or monster entered a given area, and much more. You can also define new signals
  61. tailored to your game.
  62. Summary
  63. -------
  64. Nodes, scenes, the scene tree, and signals are four core concepts in Godot that
  65. you will manipulate all the time.
  66. Nodes are your game's smallest building blocks. You combine them to create scenes
  67. that you then combine and nest into the scene tree. You can then use signals to
  68. make nodes react to events in other nodes or different scene tree branches.
  69. After this short breakdown, you probably have many questions. Bear with us as
  70. you will get many answers throughout the getting started series.