instancing.rst 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. .. _doc_instancing:
  2. Instancing
  3. ==========
  4. Rationale
  5. ---------
  6. Having a scene and throwing nodes into it might work for small projects,
  7. but as a project grows, more and more nodes are used and it can quickly
  8. become unmanageable. To solve this, Godot allows a project to be
  9. separated into several scenes. This, however, does not work the same way
  10. as in other game engines. In fact, it's quite different, so please do
  11. not skip this tutorial!
  12. To recap: A scene is a collection of nodes organized as a tree, where
  13. they can have only one single node as the tree root.
  14. .. image:: /img/tree.png
  15. In Godot, a scene can be created and saved to disk. As many scenes
  16. can be created and saved as desired.
  17. .. image:: /img/instancingpre.png
  18. Afterwards, while editing an existing or a new scene, other scenes can
  19. be instanced as part of it:
  20. .. image:: /img/instancing.png
  21. In the above picture, Scene B was added to Scene A as an instance. It
  22. may seem weird at first, but at the end of this tutorial it will make
  23. complete sense!
  24. Instancing, step by step
  25. ------------------------
  26. To learn how to do instancing, let's start with downloading a sample
  27. project: :download:`instancing.zip </files/instancing.zip>`.
  28. Unzip this project in any place of your preference. Then, add this project to
  29. the project manager using the 'Import' option:
  30. .. image:: /img/importproject.png
  31. Simply browse to inside the project location and open the "engine.cfg"
  32. file. The new project will appear on the list of projects. Edit the
  33. project by using the 'Edit' option.
  34. This project contains two scenes "ball.scn" and "container.scn". The
  35. ball scene is just a ball with physics, while container scene has a
  36. nicely shaped collision, so balls can be thrown in there.
  37. .. image:: /img/ballscene.png
  38. .. image:: /img/contscene.png
  39. Open the container scene, then select the root node:
  40. .. image:: /img/controot.png
  41. Afterwards, push the link shaped button, this is the instancing button!
  42. .. image:: /img/continst.png
  43. Select the ball scene (ball.scn), the ball should appear at the origin
  44. (0,0), move it to the center
  45. of the scene, like this:
  46. .. image:: /img/continstanced.png
  47. Press Play and Voila!
  48. .. image:: /img/playinst.png
  49. The instanced ball fell to the bottom of the pit.
  50. A little more
  51. -------------
  52. There can be as many instances as desired in a scene, just try
  53. instancing more balls, or duplicating them (Ctrl-D or duplicate button):
  54. .. image:: /img/instmany.png
  55. Then try running the scene again:
  56. .. image:: /img/instmanyrun.png
  57. Cool, huh? This is how instancing works.
  58. Editing instances
  59. -----------------
  60. Select one of the many copies of the balls and go to the property
  61. editor. Let's make it bounce a lot more, so look for the Bounce
  62. parameter and set it to 1.0:
  63. .. image:: /img/instedit.png
  64. Grey "revert" button will appear. When
  65. this button is present, it means we modified a property in the
  66. instanced scene to override a specific value in this instance. Even
  67. if that property is modified in the original scene, the custom value
  68. will always overwrite it. Pressing the revert button will restore the
  69. property to the original value that came from the scene.
  70. Conclusion
  71. ----------
  72. Instancing seems handy, but there is more to it than meets the eye!
  73. The next part of the instancing tutorial should cover the rest..