diff options
| author | Sofox | 2017-10-26 20:08:40 +0100 |
|---|---|---|
| committer | Sofox | 2017-10-26 20:42:51 +0100 |
| commit | 43cbef219b13ce9a491b353500f5d0e3dae30452 (patch) | |
| tree | 580b57080430fc4b0b7b9beffeaf6e66ba7a6337 /scene/2d/parallax_layer.cpp | |
| parent | 2987e6ce4ffc69da5efc0903cc00ce12e72d2125 (diff) | |
| download | godot-43cbef219b13ce9a491b353500f5d0e3dae30452.tar.gz godot-43cbef219b13ce9a491b353500f5d0e3dae30452.tar.zst godot-43cbef219b13ce9a491b353500f5d0e3dae30452.zip | |
Diffstat (limited to 'scene/2d/parallax_layer.cpp')
| -rw-r--r-- | scene/2d/parallax_layer.cpp | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/scene/2d/parallax_layer.cpp b/scene/2d/parallax_layer.cpp index 8fe651cb5..4a6984197 100644 --- a/scene/2d/parallax_layer.cpp +++ b/scene/2d/parallax_layer.cpp @@ -40,7 +40,7 @@ void ParallaxLayer::set_motion_scale(const Size2 &p_scale) { if (pb && is_inside_tree()) { Vector2 ofs = pb->get_final_offset(); float scale = pb->get_scroll_scale(); - set_base_offset_and_scale(ofs, scale); + set_base_offset_and_scale(ofs, scale, screen_offset); } } @@ -57,7 +57,7 @@ void ParallaxLayer::set_motion_offset(const Size2 &p_offset) { if (pb && is_inside_tree()) { Vector2 ofs = pb->get_final_offset(); float scale = pb->get_scroll_scale(); - set_base_offset_and_scale(ofs, scale); + set_base_offset_and_scale(ofs, scale, screen_offset); } } @@ -106,26 +106,28 @@ void ParallaxLayer::_notification(int p_what) { } } -void ParallaxLayer::set_base_offset_and_scale(const Point2 &p_offset, float p_scale) { +void ParallaxLayer::set_base_offset_and_scale(const Point2 &p_offset, float p_scale, const Point2 &p_screen_offset) { + screen_offset = p_screen_offset; if (!is_inside_tree()) return; if (Engine::get_singleton()->is_editor_hint()) return; - Point2 new_ofs = ((orig_offset + p_offset) * motion_scale) * p_scale + motion_offset; + + Point2 new_ofs = (screen_offset + (p_offset - screen_offset) * motion_scale) + motion_offset * p_scale + orig_offset * p_scale; + + Vector2 mirror = Vector2(1, 1); if (mirroring.x) { - double den = mirroring.x * p_scale; - new_ofs.x -= den * ceil(new_ofs.x / den); + mirror.x = -1; } if (mirroring.y) { - double den = mirroring.y * p_scale; - new_ofs.y -= den * ceil(new_ofs.y / den); + mirror.y = -1; } set_position(new_ofs); - set_scale(Vector2(1, 1) * p_scale); + set_scale(mirror * p_scale * orig_scale); } String ParallaxLayer::get_configuration_warning() const { |
