summaryrefslogtreecommitdiffstats
path: root/scene/main/canvas_item.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/main/canvas_item.cpp')
-rw-r--r--scene/main/canvas_item.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/scene/main/canvas_item.cpp b/scene/main/canvas_item.cpp
index 2d0da075ba..768c83954b 100644
--- a/scene/main/canvas_item.cpp
+++ b/scene/main/canvas_item.cpp
@@ -336,6 +336,19 @@ void CanvasItem::_notification(int p_what) {
get_parent()->connect(SNAME("child_order_changed"), callable_mp(get_viewport(), &Viewport::canvas_parent_mark_dirty).bind(get_parent()), CONNECT_REFERENCE_COUNTED);
}
+ // If using physics interpolation, reset for this node only,
+ // as a helper, as in most cases, users will want items reset when
+ // adding to the tree.
+ // In cases where they move immediately after adding,
+ // there will be little cost in having two resets as these are cheap,
+ // and it is worth it for convenience.
+ // Do not propagate to children, as each child of an added branch
+ // receives its own NOTIFICATION_ENTER_TREE, and this would
+ // cause unnecessary duplicate resets.
+ if (is_physics_interpolated_and_enabled()) {
+ notification(NOTIFICATION_RESET_PHYSICS_INTERPOLATION);
+ }
+
} break;
case NOTIFICATION_EXIT_TREE: {
ERR_MAIN_THREAD_GUARD;
@@ -360,6 +373,12 @@ void CanvasItem::_notification(int p_what) {
}
} break;
+ case NOTIFICATION_RESET_PHYSICS_INTERPOLATION: {
+ if (is_visible_in_tree() && is_physics_interpolated()) {
+ RenderingServer::get_singleton()->canvas_item_reset_physics_interpolation(canvas_item);
+ }
+ } break;
+
case NOTIFICATION_VISIBILITY_CHANGED: {
ERR_MAIN_THREAD_GUARD;
@@ -921,6 +940,10 @@ void CanvasItem::_notify_transform(CanvasItem *p_node) {
}
}
+void CanvasItem::_physics_interpolated_changed() {
+ RenderingServer::get_singleton()->canvas_item_set_interpolated(canvas_item, is_physics_interpolated());
+}
+
Rect2 CanvasItem::get_viewport_rect() const {
ERR_READ_THREAD_GUARD_V(Rect2());
ERR_FAIL_COND_V(!is_inside_tree(), Rect2());