API Reference¶
Complete API documentation for all Brine2D packages. Browse classes, interfaces, and methods organized by namespace.
Package Overview¶
Brine2D is split into multiple packages for modularity:
| Package | Purpose | NuGet |
|---|---|---|
| Brine2D.Core | Core abstractions and interfaces | |
| Brine2D.Engine | Game loop and scene management | Included in Brine2D |
| Brine2D.SDL | SDL3 rendering, input, audio | |
| Brine2D.ECS | Entity Component System | Included in Brine2D |
Quick Links¶
Most Used APIs¶
| API | Description | Package |
|---|---|---|
| Scene | Base class for game scenes | Brine2D.Core |
| IRenderer | Drawing and rendering | Brine2D.Core |
| IInputContext | Input handling | Brine2D.Core |
| IAudioService | Sound and music | Brine2D.Core |
| IEntityWorld | Entity management | Brine2D.ECS |
| Entity | Game object | Brine2D.ECS |
| Component | Component base class | Brine2D.ECS |
Browse by Package¶
Brine2D.Core¶
Core abstractions and base classes:
graph TB
Core["Brine2D.Core"]
Scene["Scene<br/>(Base class)"]
IRenderer["IRenderer<br/>(Interface)"]
IInput["IInputContext<br/>(Interface)"]
IAudio["IAudioService<br/>(Interface)"]
Core --> Scene
Core --> IRenderer
Core --> IInput
Core --> IAudio
style Core fill:#2d5016,stroke:#4ec9b0,stroke-width:3px,color:#fff
style Scene fill:#1e3a5f,stroke:#569cd6,stroke-width:2px,color:#fff
style IRenderer fill:#1e3a5f,stroke:#569cd6,stroke-width:2px,color:#fff
style IInput fill:#1e3a5f,stroke:#569cd6,stroke-width:2px,color:#fff
style IAudio fill:#1e3a5f,stroke:#569cd6,stroke-width:2px,color:#fff
Key namespaces:
- Brine2D.Core - Scene, GameTime, Color
- Brine2D.Rendering - IRenderer, ITexture
- Brine2D.Input - IInputContext, Key, MouseButton
- Brine2D.Audio - IAudioService, ISoundEffect, IMusic
Brine2D.Engine¶
Game loop and scene management:
Key classes:
- GameApplication - Application entry point
- GameApplicationBuilder - Configuration builder
- SceneManager - Scene lifecycle management
- GameTime - Frame timing information
Brine2D.Rendering¶
Rendering implementations and types:
Key classes:
- SDL3GPURenderer - GPU-accelerated renderer
- SDL3Renderer - Legacy SDL renderer
- Texture - Texture implementation
- Camera2D - 2D camera
Brine2D.Input¶
Input handling:
Key enums:
- Key - Keyboard keys
- MouseButton - Mouse buttons
- GamepadButton - Gamepad buttons
- GamepadAxis - Gamepad analog axes
Brine2D.Audio¶
Audio playback:
Key interfaces:
- IAudioService - Audio manager
- ISoundEffect - Short sound
- IMusic - Long audio (streaming)
Brine2D.ECS¶
Entity Component System:
Key classes:
- IEntityWorld - Entity container
- Entity - Game object
- Component - Component base
- GameSystem - System base (optional)
Common Patterns¶
Scene Lifecycle¶
public class GameScene : Scene
{
// 1. Constructor - inject YOUR services
public GameScene(IInputContext input, IAudioService audio)
{
// Framework properties NOT available yet
}
// 2. OnInitializeAsync - early setup
protected override Task OnInitializeAsync(CancellationToken ct)
{
// Framework properties available: Logger, World, Renderer
return Task.CompletedTask;
}
// 3. OnLoadAsync - load assets
protected override async Task OnLoadAsync(CancellationToken ct)
{
_texture = await _assets.GetOrLoadTextureAsync("sprite.png", ct);
return Task.CompletedTask;
}
// 4. OnUpdate - game logic
protected override void OnUpdate(GameTime gameTime)
{
// Update game state
}
// 5. OnRender - drawing
protected override void OnRender(GameTime gameTime)
{
// Draw sprites
}
// 6. OnUnloadAsync - cleanup
protected override Task OnUnloadAsync(CancellationToken ct)
{
// Stop audio, release resources
return Task.CompletedTask;
}
}
Rendering¶
// Access via framework property (no injection!)
protected override void OnRender(GameTime gameTime)
{
// Clear screen
Renderer.ClearColor = Color.Black;
// Draw texture
Renderer.DrawTexture(_texture, x: 100, y: 100, width: 64, height: 64);
// Draw shapes
Renderer.DrawRectangleFilled(200, 200, 50, 50, Color.Red);
Renderer.DrawCircle(300, 300, 25, Color.Blue);
// Draw text
Renderer.DrawText("Score: 100", 10, 10, Color.White);
}
Input Handling¶
// Inject IInputContext
public GameScene(IInputContext input)
{
_input = input;
}
protected override void OnUpdate(GameTime gameTime)
{
// Keyboard
if (_input.IsKeyDown(Key.W)) { }
if (_input.IsKeyPressed(Key.Space)) { }
// Mouse
var mouseX = _input.MouseX;
var mouseY = _input.MouseY;
if (_input.IsMouseButtonPressed(MouseButton.Left)) { }
// Gamepad
if (_input.IsGamepadButtonDown(0, GamepadButton.A)) { }
float leftX = _input.GetGamepadAxis(0, GamepadAxis.LeftX);
}
Entity Component System¶
// Access via framework property (no injection!)
protected override Task OnLoadAsync(CancellationToken ct)
{
// Create entity
var player = World.CreateEntity("Player");
// Add components
var health = player.AddComponent<HealthComponent>();
health.Current = 100;
health.Max = 100;
var transform = player.AddComponent<TransformComponent>();
transform.Position = new Vector2(400, 300);
return Task.CompletedTask;
}
// Query entities
var entities = World.Query<HealthComponent>().Execute();
foreach (var entity in entities)
{
var health = entity.GetComponent<HealthComponent>();
}
Conventions¶
Naming¶
| Type | Convention | Example |
|---|---|---|
| Interface | I prefix |
IRenderer, IInputContext |
| Abstract class | No prefix | Scene, Component |
| Event | Event suffix |
WindowResizedEvent |
| Component | Component suffix |
HealthComponent, TransformComponent |
| System | System suffix |
MovementSystem, RenderSystem |
Async Methods¶
All async methods follow .NET conventions:
// Methods ending in Async return Task
Task OnLoadAsync(CancellationToken ct);
Task<ITexture> GetOrLoadTextureAsync(string path, TextureScaleMode scaleMode, CancellationToken ct);
// Accept CancellationToken as last parameter
Task DoWorkAsync(string param1, int param2, CancellationToken ct);
Framework Properties¶
Three properties are set automatically by the framework:
| Property | Type | Available After |
|---|---|---|
Logger |
ILogger |
Constructor |
World |
IEntityWorld |
Constructor |
Renderer |
IRenderer |
Constructor |
Don't inject these - they're provided by the framework.
Version Compatibility¶
v0.9.0 (Current)¶
Breaking changes from v0.8.0:
- Audio API:
PlaySound()returnsnint(wasint)-
StopChannel()→StopTrack() -
Package structure:
- Split into
Brine2D+Brine2D.SDL - Namespace changes for implementations
Generate API Docs¶
Using DocFX¶
# Install DocFX
dotnet tool install -g docfx
# Generate XML documentation
dotnet build /p:GenerateDocumentationFile=true
# Create docfx.json
docfx init
# Build docs
docfx build
Using xmldoc2md¶
# Install xmldoc2md
dotnet tool install -g xmldoc2md
# Generate markdown docs
xmldoc2md Brine2D.dll --output docs/api
Related Resources¶
Guides¶
- Get Started - Quick start guide
- Tutorials - Step-by-step tutorials
- Fundamentals - Deep dive into architecture
- Samples - Working examples
External¶
- .NET API Browser - .NET base class library
- SDL3 Documentation - SDL3 API reference
Contributing¶
Help improve the API documentation:
Browse API by package:
| Package | Link |
|---|---|
| Brine2D.Core | View API → |
| Brine2D.Engine | View API → |
| Brine2D.Rendering | View API → |
| Brine2D.Input | View API → |
| Brine2D.Audio | View API → |
| Brine2D.ECS | View API → |