Class Level
This section contains all the level data. It can be found in 2 distinct forms, depending
on Project current settings: - If "Separate level files" is disabled (default):
full level data is embedded inside the main Project JSON file, - If "Separate level
files" is enabled: level data is stored in separate standalone .ldtkl
files (one
per level). In this case, the main Project JSON file will still contain most level data,
except heavy sections, like the layerInstances
array (which will be null). The
externalRelPath
string points to the ldtkl
file. A ldtkl
file is just a JSON file
containing exactly what is described below.
Properties
| Improve this Doc View SourceBgColor
Background color of the level (same as bgColor
, except the default value is
automatically used here if its value is null
)
Type | Description |
---|---|
System.String |
BgPivotX
Background image X pivot (0-1)
Type | Description |
---|---|
System.Single |
BgPivotY
Background image Y pivot (0-1)
Type | Description |
---|---|
System.Single |
BgPos
Position informations of the background image, if there is one.
Type | Description |
---|---|
LevelBackgroundPosition |
BgRelPath
The optional relative path to the level background image.
Type | Description |
---|---|
System.String |
ExternalRelPath
This value is not null if the project option "Save levels separately" is enabled. In this case, this relative path points to the level Json file.
Type | Description |
---|---|
System.String |
FieldInstances
An array containing this level custom field values.
Type | Description |
---|---|
FieldInstance[] |
Identifier
User defined unique identifier
Type | Description |
---|---|
System.String |
Iid
Unique instance identifier
Type | Description |
---|---|
System.String |
LayerInstances
An array containing all Layer instances. IMPORTANT: if the project option "Save
levels separately" is enabled, this field will be null
.
This array is sorted
in display order: the 1st layer is the top-most and the last is behind.
Type | Description |
---|---|
LayerInstance[] |
LevelBgColor
Background color of the level. If null
, the project defaultLevelBgColor
should be
used.
Type | Description |
---|---|
System.String |
LevelBgPos
An enum defining the way the background image (if any) is positioned on the level. See
__bgPos
for resulting position info. Possible values: <null
>, Unscaled
,
Contain
, Cover
, CoverDirty
, Repeat
Type | Description |
---|---|
System.Nullable<LDtkUnity.BgPos> |
Neighbours
An array listing all other levels touching this one on the world map. Since 1.4.0, this
includes levels that overlap in the same world layer, or in nearby world layers.
Only relevant for world layouts where level spatial positioning is manual (ie. GridVania,
Free). For Horizontal and Vertical layouts, this array is always empty.
Type | Description |
---|---|
NeighbourLevel[] |
PxHei
Height of the level in pixels
Type | Description |
---|---|
System.Int32 |
PxWid
Width of the level in pixels
Type | Description |
---|---|
System.Int32 |
SmartColor
The "guessed" color for this level in the editor, decided using either the background color or an existing custom field.
Type | Description |
---|---|
System.String |
Uid
Unique Int identifier
Type | Description |
---|---|
System.Int32 |
UnityBgColor
Type | Description |
---|---|
UnityEngine.Color | Background color of the level (same as |
UnityBgPivot
Type | Description |
---|---|
UnityEngine.Vector2 | Background image pivot (0-1) |
UnityLevelBgColor
Type | Description |
---|---|
UnityEngine.Color | Background color of the level. If |
UnityPxSize
Type | Description |
---|---|
UnityEngine.Vector2Int | Size of the level in pixels |
UnitySmartColor
Type | Description |
---|---|
UnityEngine.Color | The "guessed" color for this level in the editor, decided using either the background color or an existing custom field. |
UnityWorldCoord
Type | Description |
---|---|
UnityEngine.Vector2Int | World coordinate in pixels. |
UnityWorldRect
Type | Description |
---|---|
UnityEngine.RectInt | Rect of the level in pixels |
UseAutoIdentifier
If TRUE, the level identifier will always automatically use the naming pattern as defined
in Project.levelNamePattern
. Becomes FALSE if the identifier is manually modified by
user.
Type | Description |
---|---|
System.Boolean |
WorldDepth
Index that represents the "depth" of the level in the world. Default is 0, greater means
"above", lower means "below".
This value is mostly used for display only and is
intended to make stacking of levels easier to manage.
Type | Description |
---|---|
System.Int32 |
WorldX
World X coordinate in pixels.
Only relevant for world layouts where level spatial
positioning is manual (ie. GridVania, Free). For Horizontal and Vertical layouts, the
value is always -1 here.
Type | Description |
---|---|
System.Int32 |
WorldY
World Y coordinate in pixels.
Only relevant for world layouts where level spatial
positioning is manual (ie. GridVania, Free). For Horizontal and Vertical layouts, the
value is always -1 here.
Type | Description |
---|---|
System.Int32 |
Methods
| Improve this Doc View SourceFromJson(Byte[])
Used for deserializing ".ldtkl" files.
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | json | The LDtk json string to deserialize. |
Returns
Type | Description |
---|---|
Level | The deserialized level. |
UnityWorldSpaceBounds(WorldLayout, Int32, Int32)
A Rect of the level's bounds in Unity's world space.
Parameters
Type | Name | Description |
---|---|---|
LDtkUnity.WorldLayout | layout | Layout of the world. This affects how the level would be naturally positioned. |
System.Int32 | pixelsPerUnit | Main pixels per unit. |
System.Int32 | vector | Vector of the level for when creating the position for the level's layout as LinearHorizontal or LinearVertical. Otherwise the value is 0. |
Returns
Type | Description |
---|---|
UnityEngine.Rect | World space bounds of this level. |
UnityWorldSpaceCoord(WorldLayout, Int32, Int32)
A special Vector2 position that solves where the layer's position should be in Unity's world space based off of LDtk's top-left origin. If the world layout is not free style, then the positioning of the level will be automatically arranged like they do in LDtk.
Parameters
Type | Name | Description |
---|---|---|
LDtkUnity.WorldLayout | layout | Layout of the world. This affects how the level would be naturally positioned. |
System.Int32 | pixelsPerUnit | Main pixels per unit. |
System.Int32 | vector | Vector of the level for when creating the position for the level's layout as LinearHorizontal or LinearVertical. Otherwise the value is 0. |
Returns
Type | Description |
---|---|
UnityEngine.Vector2 | The bottom left corner of the level's position in world space. |