From 4dea11e31a0ec1b14b67625d4506007cd0542759 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Sat, 30 Oct 2021 19:34:21 -0400 Subject: node-2d: Fix jittery movement of nodes when paused. --- starling/node-2d.scm | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/starling/node-2d.scm b/starling/node-2d.scm index 0364a6e..f6fc190 100644 --- a/starling/node-2d.scm +++ b/starling/node-2d.scm @@ -277,6 +277,15 @@ (loop rest)))))) (camera-loop rest)))))) +(define-method (pause (display )) + ;; We need to set the last position of all objects in the tree to + ;; their current position, otherwise any moving objects will + ;; experience this weird jitter while paused because the last + ;; position will never be updated during the duration of the pause + ;; event. + (next-method) + (for-each-child remember-position/recursive display)) + ;;; ;;; 2D Scene @@ -541,8 +550,15 @@ ;; Events +(define-method (remember-position (node )) + (vec2-copy! (position node) (last-position node))) + +(define-method (remember-position/recursive (node )) + (remember-position node) + (for-each-child remember-position/recursive node)) + (define-method (update-tree (node ) dt) - (vec2-copy! (position node) (last-position node)) + (remember-position node) (when (dirty-bounding-box? node) (refresh-bounding-box node)) (next-method)) @@ -575,9 +591,18 @@ (set! (dirty-matrix? node) #t) ;; Set the initial last position to the same as the initial position ;; to avoid a brief flash where the node appears at (0, 0). - (vec2-copy! (position node) (last-position node)) + (remember-position node) (next-method)) +(define-method (pause (node )) + ;; We need to set the last position of all objects in the tree to + ;; their current position, otherwise any moving objects will + ;; experience this weird jitter while paused because the last + ;; position will never be updated during the duration of the pause + ;; event. + (next-method) + (remember-position/recursive node)) + ;;; ;;; Sprite -- cgit v1.2.3