Revert Parallax fixes from #12709 and #16795.

This reverts commits f5b6bfbbd1 and afccc72be3.

Reason: These commits seem to have caused a regression (#17764), so reverting
for now to get back to the same state as in 2.1.4-stable until a better
variant can be worked on and merged for 2.1.6.

Fixes #17764.
This commit is contained in:
Rémi Verschelde 2018-05-16 18:18:50 +02:00
parent e5c2f88541
commit f197685753
5 changed files with 13 additions and 30 deletions

View File

@ -50,11 +50,7 @@ void Camera2D::_update_scroll() {
if (viewport) {
viewport->set_canvas_transform(xform);
}
Size2 screen_size = viewport->get_visible_rect().size;
Point2 screen_offset = (anchor_mode == ANCHOR_MODE_DRAG_CENTER ? (screen_size * 0.5) : Point2());
get_tree()->call_group(SceneTree::GROUP_CALL_REALTIME, group_name, "_camera_moved", xform, screen_offset);
get_tree()->call_group(SceneTree::GROUP_CALL_REALTIME, group_name, "_camera_moved", xform);
};
}

View File

@ -47,12 +47,10 @@ void ParallaxBackground::_notification(int p_what) {
}
}
void ParallaxBackground::_camera_moved(const Matrix32 &p_transform, const Point2 &p_screen_offset) {
void ParallaxBackground::_camera_moved(const Matrix32 &p_transform) {
screen_offset = p_screen_offset;
set_scroll_scale(p_transform.get_scale().dot(Vector2(0.5, 0.5)));
set_scroll_offset(p_transform.get_origin());
set_scroll_scale(p_transform.get_scale().dot(Vector2(0.5, 0.5)));
}
void ParallaxBackground::set_scroll_scale(float p_scale) {
@ -108,9 +106,9 @@ void ParallaxBackground::_update_scroll() {
continue;
if (ignore_camera_zoom)
l->set_base_offset_and_scale(ofs, 1.0, screen_offset);
l->set_base_offset_and_scale(ofs, 1.0);
else
l->set_base_offset_and_scale(ofs, scale, screen_offset);
l->set_base_offset_and_scale(ofs, scale);
}
}

View File

@ -42,7 +42,6 @@ class ParallaxBackground : public CanvasLayer {
float scale;
Point2 base_offset;
Point2 base_scale;
Point2 screen_offset;
String group_name;
Point2 limit_begin;
Point2 limit_end;
@ -52,7 +51,7 @@ class ParallaxBackground : public CanvasLayer {
void _update_scroll();
protected:
void _camera_moved(const Matrix32 &p_transform, const Point2 &p_screen_offset);
void _camera_moved(const Matrix32 &p_transform);
void _notification(int p_what);
static void _bind_methods();

View File

@ -41,7 +41,7 @@ void ParallaxLayer::set_motion_scale(const Size2 &p_scale) {
if (is_inside_tree() && pb) {
Vector2 ofs = pb->get_final_offset();
float scale = pb->get_scroll_scale();
set_base_offset_and_scale(ofs, scale, screen_offset);
set_base_offset_and_scale(ofs, scale);
}
}
@ -61,7 +61,7 @@ void ParallaxLayer::set_motion_offset(const Size2 &p_offset) {
if (is_inside_tree() && pb) {
Vector2 ofs = pb->get_final_offset();
float scale = pb->get_scroll_scale();
set_base_offset_and_scale(ofs, scale, screen_offset);
set_base_offset_and_scale(ofs, scale);
}
}
@ -80,8 +80,7 @@ void ParallaxLayer::_update_mirroring() {
RID c = pb->get_world_2d()->get_canvas();
RID ci = get_canvas_item();
Point2 mirrorScale = mirroring * get_scale();
VisualServer::get_singleton()->canvas_set_item_mirroring(c, ci, mirrorScale);
VisualServer::get_singleton()->canvas_set_item_mirroring(c, ci, mirroring);
}
}
@ -114,21 +113,16 @@ void ParallaxLayer::_notification(int p_what) {
}
}
void ParallaxLayer::set_base_offset_and_scale(const Point2 &p_offset, float p_scale, const Point2 &p_screen_offset) {
screen_offset = p_screen_offset;
void ParallaxLayer::set_base_offset_and_scale(const Point2 &p_offset, float p_scale) {
if (!is_inside_tree())
return;
if (get_tree()->is_editor_hint())
return;
Point2 new_ofs = (screen_offset + (p_offset - screen_offset) * motion_scale) + motion_offset * p_scale + orig_offset * p_scale;
Vector2 mirror = Vector2(1, 1);
Point2 new_ofs = ((orig_offset + p_offset) * motion_scale) * p_scale + motion_offset;
if (mirroring.x) {
double den = mirroring.x * p_scale;
double before = new_ofs.x;
new_ofs.x -= den * ceil(new_ofs.x / den);
}
@ -138,9 +132,7 @@ void ParallaxLayer::set_base_offset_and_scale(const Point2 &p_offset, float p_sc
}
set_pos(new_ofs);
set_scale(Vector2(1, 1) * p_scale * orig_scale);
_update_mirroring();
set_scale(Vector2(1, 1) * p_scale);
}
String ParallaxLayer::get_configuration_warning() const {

View File

@ -43,8 +43,6 @@ class ParallaxLayer : public Node2D {
Vector2 mirroring;
void _update_mirroring();
Point2 screen_offset;
protected:
void _notification(int p_what);
static void _bind_methods();
@ -59,7 +57,7 @@ public:
void set_mirroring(const Size2 &p_mirroring);
Size2 get_mirroring() const;
void set_base_offset_and_scale(const Point2 &p_offsetf, float p_scale, const Point2 &p_screen_offset);
void set_base_offset_and_scale(const Point2 &p_offsetf, float p_scale);
virtual String get_configuration_warning() const;
ParallaxLayer();