Vixen
02b45cc4
csharp
public sealed class SpriteSheet

Many sprites on one texture: an atlas, a tile set, a character's frames.

No guide page documents this yet — the page shows what the code says about itself.

Remarks

What a sheet buys is one texture and one material for a hundred sprites, which is the difference between a hundred draws and one. The renderer never sees the sheet — it is handed sprites, and two sprites cut from the same sheet share a material and therefore share a descriptor set, which is what lets them batch. So this type is an authoring and lookup convenience over a list, and deliberately nothing more.

⚠ The lookup is built once and frozen, not searched. A sheet is read by name at load time and often by name per frame — a state machine asking for "run_03" — and a linear search over a few hundred sprites in a frame path is the kind of cost that shows up as a profile with no obvious hot spot. Built lazily, because a sheet that is only ever indexed by number should not pay for a dictionary it never asks a question of.

⚠ A class where Sprite is a record, and that cache is the reason. A record's generated equality compares every instance field including the private ones, so a sheet that had answered a lookup would stop being equal to the identical sheet that had not. Value equality over a hundred sprites was never worth having; being quietly wrong about it would have been.

Fields and properties (5)

  • public string Name

    What the sheet is called.

  • public Int2 TextureSize

    How big the texture is, in texels.

  • public Sprite[] Sprites

    The sprites, in the order they were cut.

  • public int Count

    How many sprites the sheet holds.

  • public Sprite this[int index]

    One sprite by its position in the sheet.

Methods (3)

  • public Sprite? Find(string name)

    One sprite by name.

  • public int IndexOf(string name)

    Where a name sits in the sheet.

  • public static SpriteSheet Grid(string name, Int2 textureSize, Int2 cell, int count = 0, Int2 offset = default(Int2), Int2 padding = default(Int2), Vector2 pivot = default(Vector2), NineSlice border = default(NineSlice), float pixelsPerUnit = 100)

    Cuts a texture into a grid of equally sized cells.

Used by (6)

  • SpriteAnimationVixen.Rendering
  • SpriteTestsVixen.Rendering.Tests
  • TypeRegistrationVixen.Rendering
  • Vixen_Rendering_Sprites_SpriteSheetSerializerVixen.Rendering
  • TextureImporterVixen.Editor.Assets
  • TextureImporterTestsVixen.Editor.Assets.Tests