API Surface - shmellyorc/Box GitHub Wiki
Surface
Namespace: Box.Graphics
Description: Represents a texture asset used for rendering. Wraps an underlying SFML texture, exposing its dimensions, smoothing/repeat options, source‐region helpers, and lifecycle methods for loading and disposal.
Constructors
public Surface(int width, int height, BoxColor color)
Creates a new Solid‐Color surface of given dimensions.
public Surface(int width, int height)
Creates a new White surface of given dimensions.
public Surface(Surface surface, Rect2 region, bool repeat, bool smooth)
Creates a new subsurface from an existing Surface.
Properties
Name | Type | Description |
---|---|---|
Vect2 Size |
Vect2 |
Dimensions of the surface (zero if invalid). |
Rect2 Bounds |
Rect2 |
Rectangle from origin covering the surface. |
int Width |
int |
Width in pixels. |
int Height |
int |
Height in pixels. |
string Filename |
string |
Source filename (empty if generated). |
bool Smooth |
bool |
Whether texture smoothing is enabled. |
bool Repeated |
bool |
Whether texture repeat is enabled. |
bool IsValid |
bool |
True if texture is loaded and not disposed. |
ulong Handle |
ulong |
Native handle. |
bool IsDisposed |
bool |
True once disposed. |
bool Initialized |
bool |
True once Initialize() has been called. |
Methods
Name | Description |
---|---|
Rect2 GetSource(Vect2 cellSize, int index) |
Compute cell‐based source rectangle. |
static Rect2 GetSource(Surface surface, Vect2 cellSize, int index) |
Static overload for subsurface region. |
void Initialize() |
Marks the surface as initialized. |
void Dispose() |
Releases underlying texture resources. |
Examples
// Create a 200×100 red surface:
var redSurf = new Surface(200, 100, BoxColor.AllShades.White);
// Load from file:
var img = Assets.Instance.LoadSurface("player.png");
// Create a tile from a spritesheet:
var sheet = Assets.Instance.LoadSpriteSheet("tiles.sheet");
var block = new Surface(sheet, new Rect2(new Vect2(32,32), new Vect2(32,32)), false, true);