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

TMXMapAsset.Load

Method

public RB.AssetStatus Load(string filename, RB.AssetSource source = RB.AssetSource.Resources)

Parameters

filename string File name to load from
source RB.AssetSource Source type

Returns

RB.AssetStatus

Load status

Description

Load a TMX Map asset which can be used to populate RetroBlit tilemap. 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.

If the asset is loaded via a synchronous method then Load will block until the loading is complete. If the asset is loaded via an asynchronous method then Load will immediately return and the asset loading will continue in a background thread. The status of an asynchronous loading asset can be check by looking at RBAsset.status, or by using the event system with RBAsset.OnLoadComplete to get a callback when the asset is done loading.

This method only loads the TMX Map definition, but not individual map layers. To load map layers use TMXMapAsset.LoadLayer or TMXMapAsset.LoadLayerChunk.

Example

const int LAYER_TERRAIN = 0;

TMXMapAsset mapAsset = new TMXMapAsset();
TMXMapAsset.TMXLayerLoadState terrainLayerState = new TMXMapAsset.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.LoadLayer
TMXMapAsset.LoadLayerChunk
RB.Result
RB.AssetStatus
RB.AssetSource

See Docs

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