# Big improvements and optimizations for Tiled maps handling in TCastleScene

**URL:** https://forum.castle-engine.io/t/big-improvements-and-optimizations-for-tiled-maps-handling-in-tcastlescene/726
**Category:** News
**Created:** [January 22, 2023, 11:13am UTC](https://forum.castle-engine.io/t/big-improvements-and-optimizations-for-tiled-maps-handling-in-tcastlescene/726 "2023-01-22T11:13:52Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![michalis](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/michalis/32/3_2.png) [@michalis](https://forum.castle-engine.io/u/michalis)
#### Post date: [January 22, 2023, 11:13am UTC](https://forum.castle-engine.io/t/big-improvements-and-optimizations-for-tiled-maps-handling-in-tcastlescene/726/1 "2023-01-22T11:13:52Z")

</div>

| [![Tiled isometric map in CGE editor in TCastleScene](https://forum.castle-engine.io/uploads/default/original/2X/c/cbf5e54faec711d49ba4f0a706d6c8e67755a9c5.png)](https://i0.wp.com/castle-engine.io/wp/wp-content/uploads/2023/01/tiled_editor_ortho.png?ssl=1 "Tiled isometric map in CGE editor in TCastleScene") |
| [![Tiled hexagonal map in TCastleScene](https://forum.castle-engine.io/uploads/default/original/2X/0/059c9311a43f6abf4f38e64f6e118c6d04bc0099.png)](https://i0.wp.com/castle-engine.io/wp/wp-content/uploads/2023/01/tiled_hex.png?ssl=1 "Tiled hexagonal map in TCastleScene") |
| [![Tiled map with extra objects in TCastleScene](https://forum.castle-engine.io/uploads/default/original/2X/e/ebef77e7e593825efebcd0983ef6cfc0b881bad1.png)](https://i0.wp.com/castle-engine.io/wp/wp-content/uploads/2023/01/tiled_ortho.png?ssl=1 "Tiled map with extra objects in TCastleScene") |
| [![Big Tiled map (400x400) in TCastleScene](https://forum.castle-engine.io/uploads/default/original/2X/9/9a565e28a8dfa22a31f2272820f92313aa0d616a.png)](https://i0.wp.com/castle-engine.io/wp/wp-content/uploads/2023/01/map_viewer_viewport_huge.png?ssl=1 "Big Tiled map (400x400) in TCastleScene") |
| [![Tiled map in view3dscene](https://forum.castle-engine.io/uploads/default/original/2X/a/a001f24701031a5c77e374c6ef1d28b62a6e50bc.png)](https://i0.wp.com/castle-engine.io/wp/wp-content/uploads/2023/01/view3dscene_perspective.png?ssl=1 "Tiled map in view3dscene") |
| [![Tiled map in view3dscene in 3D](https://forum.castle-engine.io/uploads/default/original/2X/7/7f28531bf83130050b36535eada4976b22eccb15.png)](https://i0.wp.com/castle-engine.io/wp/wp-content/uploads/2023/01/view3dscene_3d.png?ssl=1 "Tiled map in view3dscene in 3D") |

This post somewhat retracts yesterday’s post, because I had a busy sleepless night and fixed some issues with loading Tiled in `TCastleScene` that I mentioned yesterday 🙂 I did a significant refactor of how it works.

I’m proud to say that loading Tiled maps into `TCastleScene` is now our recommended approach to using Tiled maps. The big benefit of this approach is that you can place additional objects, like sprite sheets in `TCastleScene`, over the map easily (and specialized API to place/move units on map will appear soon too). `TCastleTiledMapControl` will soon be deprecated, in light of this.

The following improvements are done:

1. First of all, we have new example application [examples/tiled/map\_viewer\_in\_viewport](https://github.com/castle-engine/castle-engine/tree/master/examples/tiled/map_viewer_in_viewport) where you can test everything I announce today. It is a simple [Tiled](https://www.mapeditor.org/) map viewer, underneath loading Tiled map to `TCastleScene`.

You can test that it is functionally just as good, if not better, than [examples/tiled/map\_viewer](https://github.com/castle-engine/castle-engine/tree/master/examples/tiled/map_viewer) approach.

2. Huge optimization, by internally using a single draw call for all consecutive tiles using the same tileset. This allows to effortlessly support our test map 400×400 in `examples/tiled/map_viewer_in_viewport/data/maps/desert_big.tmx` with 100 FPS, at whatever zoom.

3. Support for all map types: Orthogonal, Isometric, IsometricStaggered, Hexagonal.

4. Correct support for all flip combinations (diagonal, horizontal, vertical).

5. Fixed layer Z ordering and offset application for all layer types.

6. Fixed origin (map left-bottom corner is now at 0,0).

7. Support for _“Smooth Scaling Safe Border”_, to fix rendering artifacts when using smooth scaling on tilesets without proper [alpha bleeding](https://castle-engine.io/manual_alpha_bleeding.php).

8. I’m proud that my refactor actually made the code over 2x smaller and simpler 🙂 Line count dropped 1210 -\> 510 for the `x3dloadinternaltiledmap.pas` unit.

If you like my sleepless nights’ work, [please support us on Patreon](https://www.patreon.com/castleengine) 🙂
