Skip to content

Commit ba0b93c

Browse files
committed
Merge pull request godotengine#96245 from markdibarry/prevent-autoscroll-reset
Prevent Parallax2D autoscroll reset
2 parents 8186fab + 1eda1cf commit ba0b93c

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

scene/2d/parallax_2d.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,18 @@ void Parallax2D::_notification(int p_what) {
4747
} break;
4848

4949
case NOTIFICATION_INTERNAL_PROCESS: {
50-
autoscroll_offset += autoscroll * get_process_delta_time();
51-
autoscroll_offset = autoscroll_offset.posmodv(repeat_size);
50+
Point2 offset = scroll_offset;
51+
offset += autoscroll * get_process_delta_time();
5252

53+
if (repeat_size.x) {
54+
offset.x = Math::fposmod(offset.x, repeat_size.x);
55+
}
56+
57+
if (repeat_size.y) {
58+
offset.y = Math::fposmod(offset.y, repeat_size.y);
59+
}
60+
61+
scroll_offset = offset;
5362
_update_scroll();
5463
} break;
5564

@@ -106,14 +115,14 @@ void Parallax2D::_update_scroll() {
106115
scroll_ofs *= scroll_scale;
107116

108117
if (repeat_size.x) {
109-
real_t mod = Math::fposmod(scroll_ofs.x - scroll_offset.x - autoscroll_offset.x, repeat_size.x * get_scale().x);
118+
real_t mod = Math::fposmod(scroll_ofs.x - scroll_offset.x, repeat_size.x * get_scale().x);
110119
scroll_ofs.x = screen_offset.x - mod;
111120
} else {
112121
scroll_ofs.x = screen_offset.x + scroll_offset.x - scroll_ofs.x;
113122
}
114123

115124
if (repeat_size.y) {
116-
real_t mod = Math::fposmod(scroll_ofs.y - scroll_offset.y - autoscroll_offset.y, repeat_size.y * get_scale().y);
125+
real_t mod = Math::fposmod(scroll_ofs.y - scroll_offset.y, repeat_size.y * get_scale().y);
117126
scroll_ofs.y = screen_offset.y - mod;
118127
} else {
119128
scroll_ofs.y = screen_offset.y + scroll_offset.y - scroll_ofs.y;
@@ -193,7 +202,6 @@ void Parallax2D::set_autoscroll(const Point2 &p_autoscroll) {
193202
}
194203

195204
autoscroll = p_autoscroll;
196-
autoscroll_offset = Point2();
197205

198206
_update_process();
199207
_update_scroll();

scene/2d/parallax_2d.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ class Parallax2D : public Node2D {
4747
Point2 limit_begin = Point2(-DEFAULT_LIMIT, -DEFAULT_LIMIT);
4848
Point2 limit_end = Point2(DEFAULT_LIMIT, DEFAULT_LIMIT);
4949
Point2 autoscroll;
50-
Point2 autoscroll_offset;
5150
bool follow_viewport = true;
5251
bool ignore_camera_scroll = false;
5352

0 commit comments

Comments
 (0)