From 131b16a751af282215ae0da5bc131e0a4c9489f4 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Sun, 29 Apr 2018 20:56:31 -0400 Subject: render: tiled: Invert Y coordinates of objects. * chickadee/render/tiled.scm (load-tile-map): Invert Y coordinate for objects. --- chickadee/render/tiled.scm | 20 ++++++++++++-------- 1 file 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 -- cgit v1.2.3