diff options
-rw-r--r-- | starling/node-2d.scm | 41 | ||||
-rw-r--r-- | starling/node.scm | 24 |
2 files changed, 40 insertions, 25 deletions
diff --git a/starling/node-2d.scm b/starling/node-2d.scm index a0b2746..368e8a2 100644 --- a/starling/node-2d.scm +++ b/starling/node-2d.scm @@ -314,26 +314,27 @@ (next-method)) (define-method (render* (node <node-2d>) alpha) - ;; Compute the linearly interpolated rendering position, in the case - ;; that node has moved since the last update. - (let ((p (position node)) - (lp (last-position node)) - (rp (render-position node)) - (beta (- 1.0 alpha))) - (unless (and (= (vec2-x lp) (vec2-x rp)) - (= (vec2-y lp) (vec2-y rp))) - (set-vec2-x! rp (+ (* (vec2-x p) alpha) (* (vec2-x lp) beta))) - (set-vec2-y! rp (+ (* (vec2-y p) alpha) (* (vec2-y lp) beta))) - (set! (dirty-matrix? node) #t))) - ;; Recompute dirty matrices. - (when (dirty-matrix? node) - (compute-matrices! node) - (set! (dirty-matrix? node) #f) - ;; If the parent is dirty, all the children need to be marked as - ;; dirty, too. - (for-each (lambda (node) - (set! (dirty-matrix? node) #t)) - (children node))) + (when (visible? node) + ;; Compute the linearly interpolated rendering position, in the case + ;; that node has moved since the last update. + (let ((p (position node)) + (lp (last-position node)) + (rp (render-position node)) + (beta (- 1.0 alpha))) + (unless (and (= (vec2-x lp) (vec2-x rp)) + (= (vec2-y lp) (vec2-y rp))) + (set-vec2-x! rp (+ (* (vec2-x p) alpha) (* (vec2-x lp) beta))) + (set-vec2-y! rp (+ (* (vec2-y p) alpha) (* (vec2-y lp) beta))) + (set! (dirty-matrix? node) #t))) + ;; Recompute dirty matrices. + (when (dirty-matrix? node) + (compute-matrices! node) + (set! (dirty-matrix? node) #f) + ;; If the parent is dirty, all the children need to be marked as + ;; dirty, too. + (for-each (lambda (node) + (set! (dirty-matrix? node) #t)) + (children node)))) (next-method)) (define-method (activate (node <node-2d>)) diff --git a/starling/node.scm b/starling/node.scm index 4ce46dd..51866d2 100644 --- a/starling/node.scm +++ b/starling/node.scm @@ -31,11 +31,14 @@ agenda booted? active? + visible? on-boot on-enter on-exit activate deactivate + show + hide update update* render @@ -63,7 +66,10 @@ ;; Flips to #t upon first entering a scene. (booted? #:accessor booted? #:init-form #f) ;; Flips to #t when node is part of current scene. - (active? #:accessor active? #:init-form #f)) + (active? #:accessor active? #:init-form #f) + ;; Determines whether or not the node and all of its children are + ;; rendered. + (visible? #:accessor visible? #:init-form #t #:init-keyword #:visible?)) (define (for-each-child proc node) (for-each proc (children node))) @@ -97,8 +103,9 @@ the next update represented as a ratio in the range [0, 1]." "Render NODE and all of its children, recursively. ALPHA is the distance between the previous update and the next update represented as a ratio in the range [0, 1]." - (render node alpha) - (for-each-child (lambda (child) (render* child alpha)) node)) + (when (visible? node) + (render node alpha) + (for-each-child (lambda (child) (render* child alpha)) node))) (define-method (on-boot (node <node>)) "Perform initialization tasks for NODE." @@ -136,8 +143,15 @@ represented as a ratio in the range [0, 1]." (with-agenda (agenda node) (set! (active? node) #f) (on-exit node) - (for-each-child deactivate node) - (reset-agenda))) + (for-each-child deactivate node))) + +(define-method (show (node <node>)) + "Mark NODE as visible." + (set! (visible? node) #t)) + +(define-method (hide (node <node>)) + "Mark NODE as invisible." + (set! (visible? node) #f)) ;;; |