summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2021-10-30 19:34:21 -0400
committerDavid Thompson <dthompson2@worcester.edu>2021-10-30 19:34:21 -0400
commit4dea11e31a0ec1b14b67625d4506007cd0542759 (patch)
treeb13b93f43fddd244f8422a7239691a3246a7ec9c
parent22cda3a7adb2a936210397bfc7b9f3c1ae4ce1ce (diff)
node-2d: Fix jittery movement of nodes when paused.
-rw-r--r--starling/node-2d.scm29
1 files 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 <display-2d>))
+ ;; 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 <node-2d>))
+ (vec2-copy! (position node) (last-position node)))
+
+(define-method (remember-position/recursive (node <node-2d>))
+ (remember-position node)
+ (for-each-child remember-position/recursive node))
+
(define-method (update-tree (node <node-2d>) 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 <node-2d>))
+ ;; 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