API Sprite - shmellyorc/Box GitHub Wiki

Sprite

Namespace: Box.Entities.Graphics

Description

Represents a graphical sprite entity that renders a region from a surface with optional alignment, tint, and effects. Supports scaling via the Size property and draws a debug outline when enabled.

Constructor

public Sprite(Surface surface);
public Sprite(Surface surface, Rect2 source);
public Sprite(Surface surface, Vect2 cellSize, int index);
public Sprite(Surface surface, Spritesheet sheet, string name);

Properties

Property Description
BoxColor Color Tint color applied to the sprite (default white).
SurfaceEffects Effects Surface effects applied when drawing (e.g., flipping).
VAlign VAlign Vertical alignment of the sprite within its Size.
HAlign HAlign Horizontal alignment of the sprite within its Size.
new Vect2 Size The rendered size of the sprite; setting this marks the entity and parent entities dirty for redraw.

Methods

Method Signature Description Returns
protected override void Update() Draws the sprite at Position with the configured Color, Effects, and alignment. Uses full surface if no source region. Also draws a purple debug outline if enabled. void

Examples

// Create a centered hero sprite from a spritesheet
var heroSprite = new Sprite(mySurface, mySheet, "hero")
{
	Position = new Vect2(400, 300);
	HAlign = HAlign.Center;
	VAlign = VAlign.Center;
	Layer = 10
};

mainScreen.AddEntity(heroSprite);