2D

Sprite

Sprite is the core asset of 2D projects, driving rendering and interaction through:

  • Data Source: Extracts graphic data from Texture2D
  • Rendering Control: Customizes display effects via property configurations (e.g., region, pivot)
  • Component Integration:

Properties

View and debug Sprite asset properties conveniently in the editor:

Region Property Effect Diagram
PropertyTypeDescriptionDefault Value
textureTexture2DReference to the associated texture resourcenull
widthNumberSprite width. Automatically calculated as texture pixel width / 100 (world space units) when unsettexture.width/100
heightNumberSprite height. Automatically calculated as texture pixel height / 100 (world space units) when unsettexture.height/100
regionRectTexture sampling area (normalized coordinates, range 0~1)(0,0,1,1)
pivotVector2Pivot point relative to region (bottom-left: (0,0), top-right: (1,1))(0.5,0.5)
borderVector4Border distances for nine-slice/tiling modes (left, bottom, right, top)(0,0,0,0)
belongs toSpriteAtlasAtlas containing this sprite (read-only)null

Region Cropping

  • Function: Crop a rectangular area from the texture for display
  • Example: region: (0.15, 0.3, 0.55, 0.5) crops an area starting at 15% width and 30% height of the texture, with 55% width and 50% height
    Region Property Effect Diagram

Pivot Point

  • Coordinate System: Bottom-left (0,0) → Top-right (1,1)
  • Use Cases: Control rotation/scaling anchors, align elements
    Pivot Point Diagram

Usage

Creating Sprite Assets

Generate from Uploaded Image

  1. Right-click in the Assets panel blank area
  2. Select Upload → Sprite
  3. Upload an image to auto-generate:
    • Texture asset: image-name.png
    • Sprite asset: image-name-spr.png
    Sprite Upload Workflow

Create Blank Sprite

  1. Right-click in Assets panel → Create → Sprite
  2. Manually bind a texture for usage
    Create Blank Sprite

Scripted Creation

// Create blank sprite
const sprite = new Sprite(engine);
 
// Create from existing texture
const spriteWithTexture = new Sprite(engine, texture2D);

Configuring Pivot

Use preset anchor configurations (e.g., center, corners) provided by the editor, or click Custom to input normalized coordinates.

Preset Pivot Options

Was this page helpful?