# CGE 2D game development road

**URL:** https://forum.castle-engine.io/t/cge-2d-game-development-road/725
**Category:** 2D
**Created:** [January 22, 2023, 4:40am UTC](https://forum.castle-engine.io/t/cge-2d-game-development-road/725 "2023-01-22T04:40:36Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![soastao](https://forum.castle-engine.io/letter_avatar_proxy/v4/letter/s/67e7ee/32.png) [@soastao](https://forum.castle-engine.io/u/soastao)
#### Post date: [January 22, 2023, 4:40am UTC](https://forum.castle-engine.io/t/cge-2d-game-development-road/725/1 "2023-01-22T04:40:36Z")

</div>

1、Choose a development engine

I found that CGE had 2D rendering performance problems a long time ago，I did not report this problem at the time, and transferred to the test of other engines. I tried almost all pascal engines

As we all know, there is not much choice for pascal game. I think there are only two options at present - SDL2 and CGE, other choices are not reliable.

If you choose SDL2 , it means to make all wheels yourself.

2、Use CGE’s distress

First ，I develop it in accordance with the official recommendation. Soon, I found that there is still a problem of rendering performance.

But, This time I took the initiative to report the problem. Get officially active feedback

I generally understand the problem now.

If you develop a simple 2D game, you can use the official recommendation method. The problem of poor rendering performance is not fully exposed.

If a complex 2D 'game is developed, Only the second way to use the official recommendation for the time being - Render using TDrawableImage by yourself

The 2D game I want to develop has three layers of Tile maps, there are a large number of small tiles need real -time rendering(Map similar to Diablo)

After simple testing, using TDrawableImage should be roughly satisfied.

But I found that almost all official cases did not use this method, There are very few descriptions in this way of official document.

Use TDrawableImage can meet the performance requirements, but how to combine other other UI, fonts(International text), etc. No example, no document（Disclaimer the way to give up）.I want to use Label and other designed modules in the case of using TDrawableImage’s own rendering

---

<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:53am UTC](https://forum.castle-engine.io/t/cge-2d-game-development-road/725/2 "2023-01-22T11:53:40Z")

</div>

Note that I just made another batch of optimizations to our Tiled rendering, [Big improvements and optimizations for Tiled maps handling in TCastleScene – Castle Game Engine](https://castle-engine.io/wp/2023/01/22/big-improvements-and-optimizations-for-tiled-maps-handling-in-tcastlescene/) . I encourage to try it out. And please report more exactly – testcases you make, plans you have, lacks in current API. Then I can address it better 🙂 We’re not perfect, but I need a better description of the issues you have with current solution (ideally, a reproducible test program) to fix them 🙂

As for drawing yourself: See:

- [Custom drawn 2D controls: player HUD | Manual | Castle Game Engine](https://castle-engine.io/manual_2d_ui_custom_drawn.php) ,

- [How to render 2D games with images and sprites | Manual | Castle Game Engine](https://castle-engine.io/how_to_render_2d) .

- And API docs of TDrawableImage: [Castle Game Engine: CastleGLImages: Class TDrawableImage](https://castle-engine.io/apidoc/html/CastleGLImages.TDrawableImage.html) .

Drawing using TDrawableImage is relatively trivial, it is really just loading and drawing a simple 2D image. You draw by overriding `TCastleUserInterface.Render` or `TCastleUserInterface.RenderOverChildren` methods and placing there various calls to draw things. This means:

- You can do this in a view (see [Managing Views | Manual | Castle Game Engine](https://castle-engine.io/views) about views), view has `Render` and `RenderOverChildren` methods you can override.

- You can make a custom `TCastleUserInterface` descendant like [Custom drawn 2D controls: player HUD | Manual | Castle Game Engine](https://castle-engine.io/manual_2d_ui_custom_drawn.php) shows, draw there. Then from code add this custom `TCastleUserInterface` descendant to your view.

That aren’t that many examples of using `TDrawableImage` because, as CGE high-level API gets more capable, the valid use-cases for `TDrawableImage` are more and more seldom 🙂 Whether you want to draw images in UI, or in viewport, 2D or 3D, or sprite sheets… all these cases are covered by better approaches now, and these new approaches also allow to design stuff in CGE editor. So `TDrawableImage` remains now mostly for “really special purposes when you have a valid reason to implement rendering using images yourself”.

---

<div class="post-metadata">

### Author: ![soastao](https://forum.castle-engine.io/letter_avatar_proxy/v4/letter/s/67e7ee/32.png) [@soastao](https://forum.castle-engine.io/u/soastao)
#### Post date: [January 22, 2023, 1:37pm UTC](https://forum.castle-engine.io/t/cge-2d-game-development-road/725/3 "2023-01-22T13:37:42Z")

</div>

Michalis’s work surprised me. In just two days, the performance improves huge.

Yesterday, examples/tiled/map\_viewer/data/maps/desert\_big.tmx tiled rendering incredibly faster (like 30x), Increase from 2.7FPS to 60FPS. Now, it had 600+FPS on my system(just downloaded version). Performance has increased by 220X (2.7FPS-\>600+FPS)

This makes me completely confidently developed in an officially recommended manner.

Congratulations on the improvement of CGE’s rapid advancement performance. Great work! I need more time to test, if there is a problem, I will bring test examples.

---

<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, 5:17pm UTC](https://forum.castle-engine.io/t/cge-2d-game-development-road/725/4 "2023-01-22T17:17:25Z")

</div>

Ha! Thank you for the good words!

---

<div class="post-metadata">

### Author: ![sthox](https://forum.castle-engine.io/letter_avatar_proxy/v4/letter/s/898d66/32.png) [@sthox](https://forum.castle-engine.io/u/sthox)
#### Post date: [January 26, 2023, 3:18pm UTC](https://forum.castle-engine.io/t/cge-2d-game-development-road/725/5 "2023-01-26T15:18:09Z")

</div>

“other choices are not reliable” - have you looked at ZenGL?

---

<div class="post-metadata">

### Author: ![soastao](https://forum.castle-engine.io/letter_avatar_proxy/v4/letter/s/67e7ee/32.png) [@soastao](https://forum.castle-engine.io/u/soastao)
#### Post date: [January 27, 2023, 2:54am UTC](https://forum.castle-engine.io/t/cge-2d-game-development-road/725/6 "2023-01-27T02:54:47Z")

</div>

The engine I chose before is ZenGL，It is simple and efficient

I have a long time using Zengl.

Although ZenGL hasn’t been updated for ten years.

Although Delphi and FPC is constantly updating, ZenGL has always been able to run well

I used ZenGL ：Camera、Keyboard and Mouse event management、Multi -threaded loading resources，Simple and efficient drawing API

The others are all to implement myself，Although tired, you can do whatever you want.

A few days ago, the Zengl official website couldn’t open it anymore

I encountered some incomplete places in ZenGL, for example UI part、unicode text conveniently etc,

It’s time to take a look at other choices. Write down these sadness.

More than ten years ago, I followed CGE, Compared with ZENGL, I prefer ZenGL. CGE is progressing huge on 3D, But I only focus on 2D Game development. CGE has too many convenience, and there are more restrictions. Many times I can only wait for the official update. I hope to do it myself.

---

<div class="post-metadata">

### Author: ![sthox](https://forum.castle-engine.io/letter_avatar_proxy/v4/letter/s/898d66/32.png) [@sthox](https://forum.castle-engine.io/u/sthox)
#### Post date: [January 27, 2023, 12:06pm UTC](https://forum.castle-engine.io/t/cge-2d-game-development-road/725/8 "2023-01-27T12:06:27Z")

</div>

some updates here [GitHub - Seenkao/New-ZenGL: 2D OpenGL krossplatform - library (+ full OpenGL)](https://github.com/Seenkao/New-ZenGL), it’s not from original author, but updating

---

<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 27, 2023, 10:46pm UTC](https://forum.castle-engine.io/t/cge-2d-game-development-road/725/9 "2023-01-27T22:46:10Z")

</div>

> [@soastao](#):
>
> More than ten years ago, I followed CGE, Compared with ZENGL, I prefer ZenGL. CGE is progressing huge on 3D, But I only focus on 2D Game development. CGE has too many convenience, and there are more restrictions. Many times I can only wait for the official update. I hope to do it myself.

To be clear, I hope in CGE to give you tools to deal with things in “lower level” when our “higher level” stuff is not enough.

For example, in [How to render TCastleScene between two layers of Tiledmap? - #13 by michalis](https://forum.castle-engine.io/t/how-to-render-tcastlescene-between-two-layers-of-tiledmap/727/13) you found a problem with TCastleTiledMap, recorded as [Tiled maps: Make it possible to render a character (any TCastleTransform) in a flexible way behind or in front of a layer with walls · Issue #440 · castle-engine/castle-engine · GitHub](https://github.com/castle-engine/castle-engine/issues/440) . I will fix it (though it is not trivial, so **this one** will not be done by tomorrow 🙂 )…

… but in the meantime you have the option to make drawing yourself.

As much as I wanted to encourage using ready rendering of TCastleTiledMap , I admit that [Tiled maps: Make it possible to render a character (any TCastleTransform) in a flexible way behind or in front of a layer with walls · Issue #440 · castle-engine/castle-engine · GitHub](https://github.com/castle-engine/castle-engine/issues/440) shows it is unsuitable in some cases (when you want to have a layer with walls). I didn’t predict this problem.

But you still have the option to draw map yourself using `TDrawableImage`, using the information from `TCastleTiledMapData`. These structures don’t go anywhere, and `TDrawableImage` is optimal thanks to batching introduced last week. And you can take a look at `src/scene/castletiledmap_control.inc` ( [castle-engine/src/scene/castletiledmap\_control.inc at master · castle-engine/castle-engine · GitHub](https://github.com/castle-engine/castle-engine/blob/master/src/scene/castletiledmap_control.inc) ), use this as a good starting point. If you insert character rendering in the middle of that code, than the walls will behave correctly.
