summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2018-04-29 20:56:31 -0400
committerDavid Thompson <dthompson2@worcester.edu>2018-04-29 20:56:31 -0400
commit131b16a751af282215ae0da5bc131e0a4c9489f4 (patch)
tree772c0f70b3f814fccd6d3ae56d3791aa0b4237d1
parentaa7897142cea94d5a1bcf66e48f0465a521c73f8 (diff)
render: tiled: Invert Y coordinates of objects.
* chickadee/render/tiled.scm (load-tile-map): Invert Y coordinate for objects.
-rw-r--r--chickadee/render/tiled.scm20
1 files changed, 12 insertions, 8 deletions
diff --git a/chickadee/render/tiled.scm b/chickadee/render/tiled.scm
index 802a9a2..3de534b 100644
--- a/chickadee/render/tiled.scm
+++ b/chickadee/render/tiled.scm
@@ -330,31 +330,35 @@
(properties (map parse-property
((sxpath '(properties property)) node))))
(%make-tile-layer name width height tiles properties)))
- (define (parse-polygon node)
+ (define (parse-polygon node pixel-height)
(make-polygon
(list->vector
(map (lambda (s)
(match (string-split s #\,)
((x y)
- (vec2 (string->number x) (string->number y)))))
+ (vec2 (string->number x)
+ (- pixel-height (string->number y))))))
(string-split (attr node 'points) #\space)))))
- (define (parse-object node)
+ (define (parse-object node pixel-height)
(let* ((id (attr node 'id string->number))
(name (attr node 'name))
(type (attr node 'type string->symbol))
(x (attr node 'x string->number))
- (y (attr node 'y string->number))
+ (y (- pixel-height (attr node 'y string->number)))
(width (attr node 'width string->number))
(height (attr node 'height string->number))
(shape (if (and width height)
(make-rect x y width height)
- (parse-polygon (car ((sxpath '(polygon)) node)))))
+ (parse-polygon (car ((sxpath '(polygon)) node))
+ pixel-height)))
(properties (map parse-property
((sxpath '(properties property)) node))))
(%make-map-object id name type shape properties)))
- (define (parse-object-layer node)
+ (define (parse-object-layer node pixel-height)
(let ((name (attr node 'name))
- (objects (map parse-object ((sxpath '(object)) node)))
+ (objects (map (lambda (node)
+ (parse-object node pixel-height))
+ ((sxpath '(object)) node)))
(properties (map parse-property
((sxpath '(properties property)) node))))
(%make-object-layer name objects properties)))
@@ -382,7 +386,7 @@
(('layer . _)
(parse-tile-layer node tilesets))
(('objectgroup . _)
- (parse-object-layer node))))
+ (parse-object-layer node (* height tile-height)))))
layers))
(map parse-property properties)
(make-rect 0.0