# Almost-automatic batching for TDrawableImage, Tiled rendering incredibly faster (like 30x), ability to load Tiled into TCastleScene, new isometric game demos and the plan for 2D games based on maps

**URL:** https://forum.castle-engine.io/t/almost-automatic-batching-for-tdrawableimage-tiled-rendering-incredibly-faster-like-30x-ability-to-load-tiled-into-tcastlescene-new-isometric-game-demos-and-the-plan-for-2d-games-based-on-maps/724
**Category:** News
**Created:** [January 21, 2023, 12:05pm UTC](https://forum.castle-engine.io/t/almost-automatic-batching-for-tdrawableimage-tiled-rendering-incredibly-faster-like-30x-ability-to-load-tiled-into-tcastlescene-new-isometric-game-demos-and-the-plan-for-2d-games-based-on-maps/724 "2023-01-21T12:05:04Z")
**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 21, 2023, 12:05pm UTC](https://forum.castle-engine.io/t/almost-automatic-batching-for-tdrawableimage-tiled-rendering-incredibly-faster-like-30x-ability-to-load-tiled-into-tcastlescene-new-isometric-game-demos-and-the-plan-for-2d-games-based-on-maps/724/1 "2023-01-21T12:05:04Z")

</div>

| [![isometric_game_3d designed in editor](https://forum.castle-engine.io/uploads/default/original/2X/3/3add3151912a3f26f28397a021e4f5b629d6ed9f.png)](https://i0.wp.com/castle-engine.io/wp/wp-content/uploads/2023/01/isometric_game_3d.png?ssl=1 "isometric\_game\_3d designed in editor") |
| [![isometric_game_3d with shadows](https://forum.castle-engine.io/uploads/default/original/2X/7/7bb7ec5aeb22879af1a4921f12e17eabb506b269.png)](https://i0.wp.com/castle-engine.io/wp/wp-content/uploads/2023/01/isometric_game_3d_2.png?ssl=1 "isometric\_game\_3d with shadows") |
| [![Rendering Tiled map using TCastleScene](https://forum.castle-engine.io/uploads/default/original/2X/5/5b7df9ad4dd5bdd3c645aec41e46c9b98fff3ca7.png)](https://i0.wp.com/castle-engine.io/wp/wp-content/uploads/2023/01/tiled_scene.png?ssl=1 "Rendering Tiled map using TCastleScene") |
| [![Rendering Tiled map using TCastleScene with 3D rotation](https://forum.castle-engine.io/uploads/default/original/2X/b/ba20169b5dfda2de13fe0d381fa970e06d70283b.png)](https://i0.wp.com/castle-engine.io/wp/wp-content/uploads/2023/01/map_scene_3d.png?ssl=1 "Rendering Tiled map using TCastleScene with 3D rotation") |
| [![isometric_game using scenes and viewport](https://forum.castle-engine.io/uploads/default/original/2X/0/0c765bd5d27945cbf225c8fa825122f1bc45dbfb.png)](https://i0.wp.com/castle-engine.io/wp/wp-content/uploads/2023/01/isometric_game.png?ssl=1 "isometric\_game using scenes and viewport") |
| [![Rendering big Tiled map (400x400) in map_viewer example](https://forum.castle-engine.io/uploads/default/original/2X/1/19f62d9946d16605ebdc7a3b8cacb83e2edc9ae8.png)](https://i0.wp.com/castle-engine.io/wp/wp-content/uploads/2023/01/big_map.png?ssl=1 "Rendering big Tiled map (400x400) in map\_viewer example") |
| [![Editing big map (400x400) in Tiled](https://forum.castle-engine.io/uploads/default/original/2X/8/81199b0b079e26c9b9db8aa8c6b173255ae8d9fe.png)](https://i0.wp.com/castle-engine.io/wp/wp-content/uploads/2023/01/tiled.png?ssl=1 "Editing big map (400x400) in Tiled") |

OK, this post title is probably too long 🙂 But I really want to announce a few related things, and talk about related plans. Bear with me, and read on if you’re developing 2D games using _Castle Game Engine_ with something like a map underneath.

1. I’m happy to announce a very powerful and easy to use optimization for `TDrawableImage` rendering: almost automatic batching. The way it works is really simple: if your rendering code is mostly just a sequence of calls to `TDrawableImage.Draw`, then you can surround it with `TDrawableImage.BatchingBegin` and `TDrawableImage.BatchingEnd` calls (these are class methods) to achieve a significant speedup. 

Underneath, _batching_ for `TDrawableImage` means that rendering many times the same image gets grouped into a single OpenGL(ES) draw call, and so it’s much faster. It works because GPU has great performance if you tell it to render million quads with a single draw call, while it’s quite inefficient if you use million draw calls to render one quad each.

E.g. this code actually does just 2 draw calls now, not 200:

```
TDrawableImage.BatchingBegin;
for I := 0 to 99 do
  MyDrawableImage1.Draw(100, 10 * I);
for I := 0 to 99 do
  MyDrawableImage2.Draw(100, 10 * I);
TDrawableImage.BatchingEnd;
```

This should be a great tool for people doing lots of image rendering.

2. Using the above batching, I have greatly optimized our 2D Tiled rendering control `TCastleTiledMapControl`, that now internally always activates this batching. 

3. In parallel to improving our simple 2D drawing (`TDrawableImage`, `TCastleTiledMapControl`) we also pursue another way to render 2D things in _Castle Game Engine_: render your whole 2D world as a number of objects (like `TCastleScene` and `TCastleImageTransform`) in a [viewport](https://castle-engine.io/viewport_and_scenes). 

4. Pursuing the approach to render things using scenes, with many thanks to _Matthias_ (from [Free Pascal meets SDL](https://www.freepascal-meets-sdl.net/)) you can now load Tiled maps to `TCastleScene`. Simply point `TCastleScene.URL` to a Tiled map file (`.tmx`).

5. I have been playing with creating isometric games (without Tiled help) too.

6. Finally, the optimizations necessary for great performance when you use lots of small scenes and images to render maps are really in progress 🙂

Thanks for reading! This was a complicated post, as admittedly what we do may be a bit confusing — we do pursue (and even [document](https://castle-engine.io/how_to_render_2d)) 2 approaches for 2D maps, and we improve them both. But we also have a preference which one should “win” in the future (viewport and scenes!) but it will take time to get there with full performance. I hope what we do is clearer now and that you will enjoy the journey 🙂

As always, please [ask on our Discord or forum](https://castle-engine.io/talk.php) if anything is unclear.

And we appreciate [supporting us on Patreon](https://www.patreon.com/castleengine). We also [opened the option to donate using Ethereum](https://castle-engine.io/donate_other.php) if crypto is your thing 🙂
