particle_systems_2d.rst 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. .. _doc_particle_systems_2d:
  2. Particle Systems (2D)
  3. =====================
  4. Intro
  5. -----
  6. A simple (but flexible enough for most uses) particle system is
  7. provided. Particle systems are used to simulate complex physical effects
  8. tsuch as sparks, fire, magic particles, smoke, mist, magic, etc.
  9. The idea is that a "particle" is emitted at a fixed interval and with a
  10. fixed lifetime. During his lifetime, every particle will have the same
  11. base behavior. What makes every particle different and provides a more
  12. organic look is the "randomness" associated to each parameter. In
  13. essence, creating a particle system means setting base physics
  14. parameters and then adding randomness to them.
  15. Particles2D
  16. ~~~~~~~~~~~
  17. Particle systems are added to the scene via the
  18. :ref:`Particles2D <class_Particles2D>`
  19. node. They are enabled by default and start emitting white points
  20. downwards (as affected by the gravity). This provides a reasonable
  21. starting point to start adapting it to our needs.
  22. .. image:: /img/particles1.png
  23. Texture
  24. ~~~~~~~
  25. A particle system uses a single texture (in the future this might be
  26. extended to animated textures via spritesheet). The texture is set via
  27. the relevant texture property:
  28. .. image:: /img/particles2.png
  29. Physics Variables
  30. -----------------
  31. Before taking a look at the global parameters for the particle system,
  32. let's first see what happens when the physics variables are tweaked.
  33. Direction
  34. ---------
  35. This is the base angle at which particles emit. Default is 0 (down):
  36. .. image:: /img/paranim1.gif
  37. Changing it will change the emissor direction, but gravity will still
  38. affect them:
  39. .. image:: /img/paranim2.gif
  40. This parameter is useful because, by rotating the node, gravity will
  41. also be rotated. Changing direction keeps them separate.
  42. Spread
  43. ------
  44. Spread is the angle at which particles will randomly be emitted.
  45. Increasing the spread will increase the angle. A spread of 180 will emit
  46. in all directions.
  47. .. image:: /img/paranim3.gif
  48. Linear Velocity
  49. ---------------
  50. Linear Velocity is the speed at which particles will be emitted (in
  51. pixels/sec). Speed might later be modified by gravity or other
  52. accelerations (as described further below).
  53. .. image:: /img/paranim4.gif
  54. Spin Velocity
  55. -------------
  56. Spin Velocity is the speed at which particles turn around their center
  57. (in degrees/sec).
  58. .. image:: /img/paranim5.gif
  59. Orbit Velocity
  60. --------------
  61. Orbit Velocity is used to make particles turn around their center.
  62. .. image:: /img/paranim6.gif
  63. Gravity Direction & Strength
  64. ----------------------------
  65. Gravity can be modified as in direction and strength. Gravity affects
  66. every particle currently alive.
  67. .. image:: /img/paranim7.gif
  68. Radial Acceleration
  69. -------------------
  70. If this acceleration is positive, particles are accelerated away from
  71. the center. If negative, they are absorbed towards it.
  72. .. image:: /img/paranim8.gif
  73. Tangential Acceleration
  74. -----------------------
  75. This acceleration will use the tangent vector to the center. Combined
  76. with Radial Acceleration can do nice effects.
  77. .. image:: /img/paranim9.gif
  78. Damping
  79. -------
  80. Damping applies friction to the particles, forcing them to stop. It is
  81. specially useful for sparks or explosions, which usually begin with a
  82. high linear velocity and then stop as they fade.
  83. .. image:: /img/paranim10.gif
  84. Initial Angle
  85. -------------
  86. Determines the intial angle of the particle (in degress). This parameter
  87. is mostly useful randomized.
  88. .. image:: /img/paranim11.gif
  89. Initial & Final Size
  90. --------------------
  91. Determines the intial and final scales of the particle.
  92. .. image:: /img/paranim12.gif
  93. Color Phases
  94. ------------
  95. Particles can use up to 4 color phases. Each color phase can include
  96. transparency.
  97. Phases must provide an offset value from 0 to 1, and alays in
  98. ascending order. For example, a color will begin at offset 0 and end
  99. in offset 1, but 4 colors might use diferent offsets, such as 0, 0.2,
  100. 0.8 and 1.0 for the different phases:
  101. .. image:: /img/particlecolorphases.png
  102. Will result in:
  103. .. image:: /img/paranim13.gif
  104. Global Parameters
  105. -----------------
  106. These parameters affect the behavior of the entire system.
  107. Lifetime
  108. --------
  109. The time in seconds that every particle will stay alive. When lifetime
  110. ends, a new particle is created to replace it.
  111. Lifetime: 0.5
  112. .. image:: /img/paranim14.gif
  113. Lifetime: 4.0
  114. .. image:: /img/paranim15.gif
  115. Timescale
  116. ---------
  117. It happens often that the effect achieved is perfect, except too fast or
  118. too slow. Timescale helps adjust the overall speed.
  119. Timescale everything 2x:
  120. .. image:: /img/paranim16.gif
  121. Preprocess
  122. ----------
  123. Particle systems begin with 0 particles emitted, then start emitting.
  124. This can be an inconvenience when just loading a scene and systems like
  125. a torch, mist, etc begin emitting the moment you enter. Preprocess is
  126. used to let the system process a given amount of seconds before it is
  127. actually shown the first time.
  128. Emit Timeout
  129. ------------
  130. This variable will switch emission off after given amount of seconds
  131. being on. When zero, itś disabled.
  132. Offset
  133. ------
  134. Allows to move the emission center away from the center
  135. Half Extents
  136. ------------
  137. Makes the center (by default 1 pixel) wider, to the size in pixels
  138. desired. Particles will emit randomly inside this area.
  139. .. image:: /img/paranim17.gif
  140. It is also possible to set an emission mask by using this value. Check
  141. the "Particles" menu on the 2D scene editor viewport and select your
  142. favorite texture. Opaque pixels will be used as potential emission
  143. location, while transparent ones will be ignored:
  144. .. image:: /img/paranim19.gif
  145. Local Space
  146. -----------
  147. By default this option is on, and it means that the space that particles
  148. are emitted to is contained within the node. If the node is moved, all
  149. particles are moved with it:
  150. .. image:: /img/paranim20.gif
  151. If disabled, particles will emit to global space, meaning that if the
  152. node is moved, the emissor is moved too:
  153. .. image:: /img/paranim21.gif
  154. Explosiveness
  155. -------------
  156. If lifetime is 1 and there are 10 particles, it means every particle
  157. will be emitted every 0.1 seconds. The explosiveness parameter changes
  158. this, and forces particles to be emitted all together. Ranges are:
  159. - 0: Emit all particles together.
  160. - 1: Emit particles at equal interval.
  161. Values in the middle are also allowed. This feature is useful for
  162. creating explosions or sudden bursts of particles:
  163. .. image:: /img/paranim18.gif
  164. Randomness
  165. ----------
  166. All physics parameters can be randomiez. Random variables go from 0 to
  167. 1. the formula to randomize a parameter is:
  168. ::
  169. initial_value = param_value + param_value*randomness