2D

Sprite Atlas

SpriteAtlas is a texture atlas resource designed to optimize 2D rendering performance by merging multiple sprite textures for batch rendering. Key benefits include:

Performance Boost: Reduce Draw Calls and improve rendering efficiency
Resource Optimization: Consolidate fragmented textures to minimize network requests
Memory Management: Decrease GPU memory overhead caused by frequent texture switching

Editor Usage

Create a Sprite Atlas

  1. Path: Assets Panel > Right-click Context Menu > Create > Sprite Atlas
  2. Action: A blank atlas asset will be created and can be configured in the Inspector.
Sprite Atlas creation demo

Manage Sprites

Add Sprites

MethodSteps
Via Sprite Asset1. Select target sprite 2. Inspector > Packaging > Choose atlas
Via Atlas Asset (Batch)1. Select target atlas 2. Inspector > Click Add Sprites (Supports folder batch operations)
Adding sprites via sprite asset

Remove Sprites

MethodSteps
Via Sprite AssetInspector > Packaging > Click remove icon
Via Atlas AssetInspector > Sprite List > Locate target sprite > Click remove icon

Atlas Configuration

Packing Settings

Atlas packing settings interface
ParameterDescriptionValid Range
Max Texture WidthOutput texture width constraint (Must be power of 2)(1, 2048]
Max Texture HeightOutput texture height constraint (Must be power of 2)(1, 2048]
PaddingEmpty pixels between sprites to prevent edge bleeding≥0
Allow RotationRotate sprites to improve space utilization (Experimental, disabled)true/false
Trim TransparencyAutomatically remove transparent areas (Experimental, disabled)true/false
Oversize Warning: If packed size exceeds limits, adjust max width/height or reorganize sprites.

Texture Parameters

Texture parameter settings interface
ParameterOptions
Wrap Mode U/VClamp / Repeat / Mirror
Filter ModePoint / Bilinear / Trilinear
Anisotropic LevelAnisotropic filtering level (1-16)
Generate MipmapsEnable Mipmap chain generation

Scripting Guide

CLI Packaging Tool

# Install globally  
npm i @galacean/tools-atlas -g  
 
# Package assets (Example: input dir=assets, output name=ui_atlas)  
galacean-tool-atlas p assets -o ui_atlas  
ParameterDescriptionDefault
-f/--formatOutput format (galacean only)galacean
-mw/--maxWidthMax texture width1024
-mh/--maxHeightMax texture height1024
-p/--paddingPixel padding between sprites1

📘 Full Parameter Docs

Runtime Loading & Usage

// Load atlas  
engine.resourceManager.load<SpriteAtlas>({  
  url: "https://cdn.com/ui_atlas.atlas",  
  type: AssetType.SpriteAtlas  
}).then((atlas) => {  
  // Get all sprites  
  const allSprites = atlas.sprites;  
 
  // Retrieve by exact name  
  const heroSprite = atlas.getSprite("hero_idle");  
 
  // Batch retrieve duplicates  
  const coinSprites = atlas.getSprites("coin", []);  
});  
Ensure atlas files (.atlas and .png) reside in the same CDN directory, e.g., https://cdnDir/atlasName.atlas and https://cdnDir/atlasName.png.

Best Practices

Optimization Tips

  1. Size Planning: Set reasonable max dimensions (e.g., 1024x1024) to avoid oversizing.
  2. Preview Utilization: Use Pack & Preview to check space efficiency (Aim ≥80%).
Atlas utilization preview

API Reference

Core ClassKey Methods/PropertiesDescription
SpriteAtlassprites: Sprite[]All sprites in the atlas
getSprite(name: string)Get first sprite by name
getSprites(name: string)Get all sprites with matching name

Was this page helpful?