diff options
-rw-r--r-- | chickadee/render/tiled.scm | 20 |
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 |