diff options
author | JFonS <joan.fonssanchez@gmail.com> | 2018-11-13 18:19:16 +0100 |
---|---|---|
committer | JFonS <joan.fonssanchez@gmail.com> | 2018-11-13 23:25:05 +0100 |
commit | cbfb7bd613a697503fe046428b0fd0fc08829926 (patch) | |
tree | 7172e1b4a10c07d254bc83eda66e0e6fe30a0b27 /scene/2d/cpu_particles_2d.cpp | |
parent | 7f347cc31a121a059e881d4df52add49642dcca3 (diff) |
Make 2D particles work OOTB (again)
Diffstat (limited to 'scene/2d/cpu_particles_2d.cpp')
-rw-r--r-- | scene/2d/cpu_particles_2d.cpp | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/scene/2d/cpu_particles_2d.cpp b/scene/2d/cpu_particles_2d.cpp index bc2bd9a1c5..a1b624a246 100644 --- a/scene/2d/cpu_particles_2d.cpp +++ b/scene/2d/cpu_particles_2d.cpp @@ -153,13 +153,19 @@ CPUParticles2D::DrawOrder CPUParticles2D::get_draw_order() const { return draw_order; } -void CPUParticles2D::_generate_mesh_texture() { +void CPUParticles2D::_update_mesh_texture() { + Size2 tex_size; + if (texture.is_valid()) { + tex_size = texture->get_size(); + } else { + tex_size = Size2(1, 1); + } PoolVector<Vector2> vertices; - vertices.push_back(Vector2(-0.5, -0.5)); - vertices.push_back(Vector2(0.5, -0.5)); - vertices.push_back(Vector2(0.5, 0.5)); - vertices.push_back(Vector2(-0.5, 0.5)); + vertices.push_back(-tex_size * 0.5); + vertices.push_back(-tex_size * 0.5 + Vector2(tex_size.x, 0)); + vertices.push_back(-tex_size * 0.5 + Vector2(tex_size.x, tex_size.y)); + vertices.push_back(-tex_size * 0.5 + Vector2(0, tex_size.y)); PoolVector<Vector2> uvs; uvs.push_back(Vector2(0, 0)); uvs.push_back(Vector2(1, 0)); @@ -193,6 +199,7 @@ void CPUParticles2D::set_texture(const Ref<Texture> &p_texture) { texture = p_texture; update(); + _update_mesh_texture(); } Ref<Texture> CPUParticles2D::get_texture() const { @@ -234,9 +241,12 @@ String CPUParticles2D::get_configuration_warning() const { CanvasItemMaterial *mat = Object::cast_to<CanvasItemMaterial>(get_material().ptr()); if (get_material().is_null() || (mat && !mat->get_particles_animation())) { - if (warnings != String()) - warnings += "\n"; - warnings += "- " + TTR("CPUParticles2D animation requires the usage of a CanvasItemMaterial with \"Particles Animation\" enabled."); + if (get_param(PARAM_ANIM_SPEED) != 0.0 || get_param(PARAM_ANIM_OFFSET) != 0.0 || + get_param_curve(PARAM_ANIM_SPEED).is_valid() || get_param_curve(PARAM_ANIM_OFFSET).is_valid()) { + if (warnings != String()) + warnings += "\n"; + warnings += "- " + TTR("CPUParticles2D animation requires the usage of a CanvasItemMaterial with \"Particles Animation\" enabled."); + } } return warnings; @@ -1396,7 +1406,7 @@ CPUParticles2D::CPUParticles2D() { update_mutex = Mutex::create(); #endif - _generate_mesh_texture(); + _update_mesh_texture(); } CPUParticles2D::~CPUParticles2D() { |