diff options
author | David Thompson <davet@gnu.org> | 2019-05-08 17:29:24 -0400 |
---|---|---|
committer | David Thompson <davet@gnu.org> | 2019-05-08 17:29:24 -0400 |
commit | 116cdfdee1aa562eac0e8d326a792cbe6067af12 (patch) | |
tree | a9f87b08aef4bf78108fbbeb300f5957c0ce11eb | |
parent | 95519e678ff76ca00eabb52829493279c658ab71 (diff) |
render: tiled: Parse out tile flip bits.
* chickadee/render/tiled.scm (load-tile-map): Parse out the 3 flip
bits from each tile id.
-rw-r--r-- | chickadee/render/tiled.scm | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/chickadee/render/tiled.scm b/chickadee/render/tiled.scm index 8e8b8f4..1a4c200 100644 --- a/chickadee/render/tiled.scm +++ b/chickadee/render/tiled.scm @@ -280,8 +280,17 @@ (if (attr node 'source) (parse-external-tileset node) (parse-internal-tileset node (first-gid node)))) - (define (tile-gid->map-tile gid tilesets x y tile-width tile-height) - (let* ((tileset (find (lambda (t) + (define (tile-gid->map-tile raw-gid tilesets x y tile-width tile-height) + ;; The top 3 bits of the tile gid are flags for various types of + ;; flipping. + ;; + ;; TODO: Respect the flipping settings. + (let* ((flipped-horizontally? (> (logand raw-gid #x80000000) 0)) + (flipped-vertically? (> (logand raw-gid #x40000000) 0)) + (flipped-diagonally? (> (logand raw-gid #x20000000) 0)) + ;; Remove the upper 3 bits to get the true tile id. + (gid (logand raw-gid #x1FFFFFFF)) + (tileset (find (lambda (t) (and (>= gid (tileset-first-gid t)) (< gid (+ (tileset-first-gid t) (tileset-size t))))) |