particles_2d.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /**************************************************************************/
  2. /* particles_2d.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef PARTICLES_2D_H
  31. #define PARTICLES_2D_H
  32. #include "core/rid.h"
  33. #include "scene/2d/node_2d.h"
  34. #include "scene/resources/texture.h"
  35. class Particles2D : public Node2D {
  36. private:
  37. GDCLASS(Particles2D, Node2D);
  38. public:
  39. enum DrawOrder {
  40. DRAW_ORDER_INDEX,
  41. DRAW_ORDER_LIFETIME,
  42. };
  43. private:
  44. RID particles;
  45. bool emitting = false;
  46. bool active = false;
  47. bool signal_canceled = false;
  48. bool one_shot = false;
  49. int amount;
  50. float lifetime;
  51. float pre_process_time;
  52. float explosiveness_ratio;
  53. float randomness_ratio;
  54. float speed_scale;
  55. Rect2 visibility_rect;
  56. bool local_coords;
  57. int fixed_fps;
  58. bool fractional_delta;
  59. #ifdef TOOLS_ENABLED
  60. bool show_visibility_rect;
  61. #endif
  62. Ref<Material> process_material;
  63. DrawOrder draw_order;
  64. Ref<Texture> texture;
  65. Ref<Texture> normal_map;
  66. void _update_particle_emission_transform();
  67. double time = 0.0;
  68. double emission_time = 0.0;
  69. double active_time = 0.0;
  70. protected:
  71. static void _bind_methods();
  72. virtual void _validate_property(PropertyInfo &property) const;
  73. void _notification(int p_what);
  74. public:
  75. void set_emitting(bool p_emitting);
  76. void set_amount(int p_amount);
  77. void set_lifetime(float p_lifetime);
  78. void set_one_shot(bool p_enable);
  79. void set_pre_process_time(float p_time);
  80. void set_explosiveness_ratio(float p_ratio);
  81. void set_randomness_ratio(float p_ratio);
  82. void set_visibility_rect(const Rect2 &p_visibility_rect);
  83. void set_use_local_coordinates(bool p_enable);
  84. void set_process_material(const Ref<Material> &p_material);
  85. void set_speed_scale(float p_scale);
  86. #ifdef TOOLS_ENABLED
  87. void set_show_visibility_rect(bool p_show_visibility_rect);
  88. #endif
  89. bool is_emitting() const;
  90. int get_amount() const;
  91. float get_lifetime() const;
  92. bool get_one_shot() const;
  93. float get_pre_process_time() const;
  94. float get_explosiveness_ratio() const;
  95. float get_randomness_ratio() const;
  96. Rect2 get_visibility_rect() const;
  97. bool get_use_local_coordinates() const;
  98. Ref<Material> get_process_material() const;
  99. float get_speed_scale() const;
  100. void set_fixed_fps(int p_count);
  101. int get_fixed_fps() const;
  102. void set_fractional_delta(bool p_enable);
  103. bool get_fractional_delta() const;
  104. void set_draw_order(DrawOrder p_order);
  105. DrawOrder get_draw_order() const;
  106. void set_texture(const Ref<Texture> &p_texture);
  107. Ref<Texture> get_texture() const;
  108. void set_normal_map(const Ref<Texture> &p_normal_map);
  109. Ref<Texture> get_normal_map() const;
  110. virtual String get_configuration_warning() const;
  111. void restart();
  112. Rect2 capture_rect() const;
  113. Particles2D();
  114. ~Particles2D();
  115. };
  116. VARIANT_ENUM_CAST(Particles2D::DrawOrder)
  117. #endif // PARTICLES_2D_H