AudioAsset
Ease
FastString
FontAsset
NineSlice
PackedSprite
PackedSpriteID
RB
   HardwareSettings
   IRetroBlitGame
RBAsset
Rect2i
ShaderAsset
SoundReference
SpriteGrid
SpriteSheetAsset
TMXMapAsset
   TMXLayer
   TMXLayerLoadState
   TMXObject
   TMXObjectGroup
   TMXProperties
Vector2i

TMXMapAsset.LoadLayer

Method

public TMXLayerLoadState LoadLayer(string sourceLayerName, int destinationLayer, SpriteSheetAsset spriteSheet = null)
public TMXLayerLoadState LoadLayer(string sourceLayerName, int destinationLayer, Rect2i sourceRect, Vector2i destPos)
public TMXLayerLoadState LoadLayer(string sourceLayerName, int destinationLayer, PackedSpriteID [] packedSpriteLookup)
public TMXLayerLoadState LoadLayer(string sourceLayerName, int destinationLayer, Rect2i sourceRect, Vector2i destPos, PackedSpriteID [] packedSpriteLookup)
public TMXLayerLoadState LoadLayer(string sourceLayerName, int destinationLayer, PackedSprite [] packedSpriteLookup)
public TMXLayerLoadState LoadLayer(string sourceLayerName, int destinationLayer, Rect2i sourceRect, Vector2i destPos, PackedSprite [] packedSpriteLookup)
public TMXLayerLoadState LoadLayer(string sourceLayerName, int destinationLayer, FastString [] packedSpriteLookup)
public TMXLayerLoadState LoadLayer(string sourceLayerName, int destinationLayer, Rect2i sourceRect, Vector2i destPos, FastString [] packedSpriteLookup)
public TMXLayerLoadState LoadLayer(string sourceLayerName, int destinationLayer, string [] packedSpriteLookup)
public TMXLayerLoadState LoadLayer(string sourceLayerName, int destinationLayer, Rect2i sourceRect, Vector2i destPos, string [] packedSpriteLookup)

Parameters

sourceLayerName string Name of the TMX layer. Duplicate layer names are not supported
destinationLayer int The RetroBlit layer to load into
spriteSheet SpriteSheetAsset Sprite sheet to use for this layer
sourceRect Rect2i Source rectangular tilemap area to load from
destPos Vector2i Destination position in the RetroBlit layer in tile coordinates
packedSpriteLookup PackedSpriteID [] Lookup table for translating TMX tile indexes to packed sprites

Returns

TMXLayerLoadState

Layer loading state

Description

Load a TMX map layer from a standard map. For infinite maps use TMXMapAsset.LoadLayerChunk instead. There are various asset sources supported:

  • Resources - Synchronously loaded TMX Map assets from a Resources folder. This was the only asset source supported in RetroBlit prior to 3.0.
  • ResourcesAsync - Asynchronously loaded TMX Map assets from a Resources folder.
  • WWW - Asynchronously loaded TMX Map assets from a URL.
  • AddressableAssets - Asynchronously loaded TMX Map assets from Unity Addressable Assets.

The layer into which the layer tile data is loaded if specified by destinationLayer. Optionally a sub-section of a layer can be loaded by specifying sourceRect. The destination position of the tile data can also be specified with destPos.

The sprite sheet or sprite pack can be specified for this layer by passing spriteSheet parameter, or later by RB.MapLayerSpriteSheetSet. If a sprite pack is specified then a lookup array can be passed using packedSpriteLookup, which will help RetroBlit translate from tilemap sprite indices to packed sprites.

Besides tile sprite information TMXMapAsset.LoadLayer also loads TMXProperties for each tile. These properties can be set inside of Tiled. This can be very useful for defining gameplay affecting properties such as whether a particular tile is "blocking".

Example

const int LAYER_TERRAIN = 0;

TMXMapAsset mapAsset = new TMXMapAsset();
TMXMapAsset.TMXLayerLoadState terrainLayerState = new TMXLayerLoadState();
bool mapSet = false;

public void Initialize()
{
    // Load asset from Resources asynchronously. This method call will immediately return without blocking.
    mapAsset.Load("main_map"RB.AssetSource.ResourcesAsync);
}

public void Update()
{
    // If the map finished loading, but the layer has not started loading yet then load it now
    if (mapAsset.status == RB.AssetStatus.Ready && layerState.status == RB.AssetStatus.Invalid)
    {
        layerState = mapAsset.LoadLayer("Terrain", LAYER_TERRAIN, mySpriteSheet);
    }
}

public void Render()
{
    // Don't draw anything until the map layer is loaded
    if (layerState.status != RB.AssetStatus.Ready)
    {
        return;
    }

    RB.SpriteSheetSet(spriteMain);
    RB.DrawMapLayer(LAYER_TERRAIN);
}

See Also

TMXMapAsset.Load
TMXMapAsset.LoadLayerChunk
RB.Result
RB.AssetStatus
RB.AssetSource

See Docs

Features - Tilemaps
Features - Tiled TMX Support
Features - Asynchronous Asset Loading