aboutsummaryrefslogtreecommitdiff
path: root/world.scm
diff options
context:
space:
mode:
Diffstat (limited to 'world.scm')
-rw-r--r--world.scm31
1 files changed, 15 insertions, 16 deletions
diff --git a/world.scm b/world.scm
index 1f1b457..e637e90 100644
--- a/world.scm
+++ b/world.scm
@@ -95,24 +95,23 @@
(loop (cdr es) (cons (cons gid e) acc))))
(loop (cdr es) acc))))))
+ (define (sync-member-to-origin e origins)
+ (let* ((gid (entity-ref e #:group-id #f))
+ (o (and gid (not (entity-ref e #:group-origin? #f))
+ (assq gid origins))))
+ (if o
+ (let ((origin (cdr o)))
+ (entity-set (entity-set e #:x (+ (entity-ref origin #:x 0)
+ (entity-ref e #:group-local-x 0)))
+ #:y (+ (entity-ref origin #:y 0)
+ (entity-ref e #:group-local-y 0))))
+ e)))
+
;; Snap member #:x/#:y to origin + #:group-local-x/y. Call after moving origins (tweens, etc.).
(define (scene-sync-groups! scene)
- (let* ((ents (scene-entities scene))
- (origins (group-origin-alist ents)))
+ (let ((origins (group-origin-alist (scene-entities scene))))
(scene-entities-set! scene
- (map (lambda (e)
- (if (and (entity-ref e #:group-id #f)
- (not (entity-ref e #:group-origin? #f)))
- (let* ((gid (entity-ref e #:group-id))
- (o (assq gid origins)))
- (if o
- (let ((origin (cdr o)))
- (entity-set (entity-set e #:x (+ (entity-ref origin #:x 0)
- (entity-ref e #:group-local-x 0)))
- #:y (+ (entity-ref origin #:y 0)
- (entity-ref e #:group-local-y 0))))
- e))
- e))
- ents))
+ (map (lambda (e) (sync-member-to-origin e origins))
+ (scene-entities scene)))
scene))
)