| 1 |
{ |
| 2 |
Copyright 2015-2024 Tomasz Wojtyś, Michalis Kamburelis. |
| 3 |
|
| 4 |
This file is part of "Castle Game Engine". |
| 5 |
|
| 6 |
"Castle Game Engine" is free software; see the file COPYING.txt, |
| 7 |
included in this distribution, for details about the copyright. |
| 8 |
|
| 9 |
"Castle Game Engine" is distributed in the hope that it will be useful, |
| 10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 12 |
|
| 13 |
---------------------------------------------------------------------------- |
| 14 |
} |
| 15 |
|
| 16 |
{ Loading and rendering maps created in Tiled. |
| 17 |
See @url(https://castle-engine.io/tiled_maps manual about using Tiled maps) |
| 18 |
for more details. |
| 19 |
|
| 20 |
Most basic usage is to add @link(TCastleTiledMap) component to a viewport |
| 21 |
and set @link(TCastleTiledMap.URL) to load your Tiled map (TMX file). |
| 22 |
You can test it using CGE editor. |
| 23 |
|
| 24 |
See the examples in Castle Game Engine: |
| 25 |
@url(https://github.com/castle-engine/castle-engine/tree/master/examples/tiled examples/tiled/). } |
| 26 |
unit CastleTiledMap; |
| 27 |
|
| 28 |
{$I castleconf.inc} |
| 29 |
|
| 30 |
interface |
| 31 |
|
| 32 |
uses |
| 33 |
Classes, SysUtils, DOM, XMLRead, base64, |
| 34 |
{$ifdef FPC} zstream {$else} { from Vampyre } DZLib {$endif}, |
| 35 |
Generics.Collections, CastleInternalFileMonitor, |
| 36 |
CastleVectors, CastleColors, CastleUtils, CastleUriUtils, CastleXmlUtils, |
| 37 |
CastleLog, CastleStringUtils, CastleUIControls, CastleGLImages, CastleTransform, |
| 38 |
CastleRectangles, CastleClassUtils, CastleRenderOptions, CastleScene, X3DNodes; |
| 39 |
|
| 40 |
{$define read_interface} |
| 41 |
{$I castletiledmap_data.inc} |
| 42 |
{$I castletiledmap_control.inc} |
| 43 |
{$I castletiledmap_scene.inc} |
| 44 |
{$undef read_interface} |
| 45 |
|
| 46 |
const |
| 47 |
LoadTiledMap_FileFilters = 'Tiled Map (*.tmx)|*.tmx|All Files|*'; |
| 48 |
|
| 49 |
implementation |
| 50 |
|
| 51 |
uses Math, |
| 52 |
CastleComponentSerialize, CastleImages, CastleRenderContext, |
| 53 |
X3DLoadInternalTiledMap, CastleGLUtils, CastleDownload; |
| 54 |
|
| 55 |
{$define read_implementation} |
| 56 |
{$I castletiledmap_data.inc} |
| 57 |
{$I castletiledmap_control.inc} |
| 58 |
{$I castletiledmap_scene.inc} |
| 59 |
{$undef read_implementation} |
| 60 |
|
| 61 |
var |
| 62 |
R: TRegisteredComponent; |
| 63 |
initialization |
| 64 |
R := TRegisteredComponent.Create; |
| 65 |
{$warnings off} // using deprecated, to keep reading it from castle-user-interface working |
| 66 |
R.ComponentClass := TCastleTiledMapControl; |
| 67 |
{$warnings on} |
| 68 |
R.Caption := ['Tiled Map Control']; |
| 69 |
R.IsDeprecated := true; |
| 70 |
RegisterSerializableComponent(R); |
| 71 |
|
| 72 |
RegisterSerializableComponent(TCastleTiledMap, 'Tiled Map'); |
| 73 |
end. |