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

SpriteSheetAsset.Load

Method

public RB.AssetStatus Load(string path, SheetType sheetType = SheetType.SpriteSheet, RB.AssetSource source = RB.AssetSource.Resources)
public RB.AssetStatus Load(RenderTexture existingTexture)
public RB.AssetStatus Load(Texture2D existingTexture)

Parameters

path string Path of the sprite sheet
sheetType SheetType The type of sprite sheet, either SheetType.SpriteSheet or SheetType.SpritePack
source RB.AssetSource Source type of the asset
existingTexture RenderTexture Existing texture

Returns

RB.AssetStatus

Load status

Description

Load sprites which can be drawn to display or offscreen surfaces. This method is used to load both SheetType.SpriteSheet and SheetType.SpritePack. There are various asset sources supported:

  • Resources - Synchronously loaded sprite assets from a Resources folder. This was the only asset source supported in RetroBlit prior to 3.0.
  • ResourcesAsync - Asynchronously loaded sprite assets from a Resources folder.
  • WWW - Asynchronously loaded sprite assets from a URL.
  • AddressableAssets - Asynchronously loaded sprite assets from Unity Addressable Assets.
  • Existing Assets - Synchronously loaded sprite assets from an existing Unity Texture2D or RenderTexture.

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.

Example

SpriteSheetAsset spriteMain = new SpriteSheetAsset();

public void Initialize()
{
    // Load asset from Resources asynchronously. This method call will immediately return without blocking.
    spriteMain.Load("main_spritepack"RB.SheetType.SpritePack, RB.AssetSource.ResourcesAsync);
}

public void Render()
{
    // Don't draw anything until sprites are loaded
    if (spriteMain.status != RB.AssetStatus.Ready)
    {
        return;
    }

    RB.SpriteSheetSet(spriteMain);
    RB.DrawSprite("hero/walk1", playerPos);
}

See Also

RB.Result
RB.AssetStatus
RB.AssetSource

See Docs

Features - Sprites
Features - Asynchronous Asset Loading