summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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