Remove ParallaxLayer's invalid dependence on screen_offset

This commit is contained in:
Marcel Admiraal 2022-02-26 18:47:22 +00:00
parent 0393057e36
commit aeff4cf6f3
3 changed files with 7 additions and 11 deletions

View File

@ -102,9 +102,9 @@ void ParallaxBackground::_update_scroll() {
} }
if (ignore_camera_zoom) { if (ignore_camera_zoom) {
l->set_base_offset_and_scale((ofs + screen_offset * (scale - 1)) / scale, 1.0, screen_offset); l->set_base_offset_and_scale((ofs + screen_offset * (scale - 1)) / scale, 1.0);
} else { } else {
l->set_base_offset_and_scale(ofs, scale, screen_offset); l->set_base_offset_and_scale(ofs, scale);
} }
} }
} }

View File

@ -39,7 +39,7 @@ void ParallaxLayer::set_motion_scale(const Size2 &p_scale) {
if (pb && is_inside_tree()) { if (pb && is_inside_tree()) {
Vector2 ofs = pb->get_final_offset(); Vector2 ofs = pb->get_final_offset();
real_t scale = pb->get_scroll_scale(); real_t scale = pb->get_scroll_scale();
set_base_offset_and_scale(ofs, scale, screen_offset); set_base_offset_and_scale(ofs, scale);
} }
} }
@ -54,7 +54,7 @@ void ParallaxLayer::set_motion_offset(const Size2 &p_offset) {
if (pb && is_inside_tree()) { if (pb && is_inside_tree()) {
Vector2 ofs = pb->get_final_offset(); Vector2 ofs = pb->get_final_offset();
real_t scale = pb->get_scroll_scale(); real_t scale = pb->get_scroll_scale();
set_base_offset_and_scale(ofs, scale, screen_offset); set_base_offset_and_scale(ofs, scale);
} }
} }
@ -111,9 +111,7 @@ void ParallaxLayer::_notification(int p_what) {
} }
} }
void ParallaxLayer::set_base_offset_and_scale(const Point2 &p_offset, real_t p_scale, const Point2 &p_screen_offset) { void ParallaxLayer::set_base_offset_and_scale(const Point2 &p_offset, real_t p_scale) {
screen_offset = p_screen_offset;
if (!is_inside_tree()) { if (!is_inside_tree()) {
return; return;
} }
@ -121,7 +119,7 @@ void ParallaxLayer::set_base_offset_and_scale(const Point2 &p_offset, real_t p_s
return; return;
} }
Point2 new_ofs = (screen_offset + (p_offset - screen_offset) * motion_scale) + motion_offset * p_scale + orig_offset * p_scale; Point2 new_ofs = p_offset * motion_scale + motion_offset * p_scale + orig_offset * p_scale;
if (mirroring.x) { if (mirroring.x) {
real_t den = mirroring.x * p_scale; real_t den = mirroring.x * p_scale;

View File

@ -43,8 +43,6 @@ class ParallaxLayer : public Node2D {
Vector2 mirroring; Vector2 mirroring;
void _update_mirroring(); void _update_mirroring();
Point2 screen_offset;
protected: protected:
void _notification(int p_what); void _notification(int p_what);
static void _bind_methods(); static void _bind_methods();
@ -59,7 +57,7 @@ public:
void set_mirroring(const Size2 &p_mirroring); void set_mirroring(const Size2 &p_mirroring);
Size2 get_mirroring() const; Size2 get_mirroring() const;
void set_base_offset_and_scale(const Point2 &p_offset, real_t p_scale, const Point2 &p_screen_offset); void set_base_offset_and_scale(const Point2 &p_offset, real_t p_scale);
TypedArray<String> get_configuration_warnings() const override; TypedArray<String> get_configuration_warnings() const override;
ParallaxLayer(); ParallaxLayer();