Grafik
Framebuffer-Rendering auf der Nintendo Switch — Primitiven, Text, Texturen und Alpha-Blending.
Grafik-Modus wird aktiviert durch
Graphics.Init(1280, 720) in OnInit(). Ohne diesen Aufruf läuft die App im Console-Modus.Initialisierung
public class MyApp : SwitchApp
{
public override void OnInit()
{
Graphics.Init(1280, 720); // Framebuffer aktivieren
}
public override void OnFrame()
{
Graphics.FillScreen(Color.Black); // Jeden Frame leeren
// ... zeichnen
}
}Basis-Primitiven
| Methode | Beschreibung |
|---|---|
| Graphics.Init(w, h) | Framebuffer-Modus aktivieren |
| Graphics.FillScreen(color) | Bildschirm komplett füllen |
| Graphics.SetPixel(x, y, color) | Einzelnen Pixel setzen |
| Graphics.DrawRect(x, y, w, h, color) | Rechteck-Outline |
| Graphics.FillRect(x, y, w, h, color) | Gefülltes Rechteck |
| Graphics.DrawLine(x0, y0, x1, y1, color) | Linie (Bresenham) |
| Graphics.DrawCircle(cx, cy, r, color) | Kreis-Outline |
| Graphics.FillCircle(cx, cy, r, color) | Gefüllter Kreis |
Text
| Methode | Beschreibung |
|---|---|
| Graphics.DrawText(x, y, text, color, scale) | Text mit 8×8 Bitmap-Font |
| Graphics.DrawChar(x, y, c, color, scale) | Einzelnes Zeichen |
| Graphics.DrawTextShadow(x, y, text, color, shadow, scale) | Text mit 1px-Schatten |
| Graphics.MeasureTextWidth(text, scale) | Text-Breite in Pixeln |
| Graphics.MeasureTextHeight(scale) | Text-Höhe in Pixeln |
Graphics.DrawText(100, 100, "Hello Switch!", Color.White, 2);
// scale=2 → 16px hohe Zeichen (8px Font × 2)
Graphics.DrawTextShadow(100, 140, "Mit Schatten", Color.White, Color.Black, 2);
int w = Graphics.MeasureTextWidth("Text", 2); // Breite ermittelnErweiterte Primitiven
| Methode | Beschreibung |
|---|---|
| Graphics.DrawTriangle(x0,y0, x1,y1, x2,y2, color) | Dreieck-Outline |
| Graphics.FillTriangle(x0,y0, x1,y1, x2,y2, color) | Gefülltes Dreieck (Scanline) |
| Graphics.DrawEllipse(cx, cy, rx, ry, color) | Ellipse-Outline |
| Graphics.FillEllipse(cx, cy, rx, ry, color) | Gefüllte Ellipse |
| Graphics.DrawRoundedRect(x, y, w, h, r, color) | Abgerundetes Rechteck |
| Graphics.FillRoundedRect(x, y, w, h, r, color) | Gefülltes abgerundetes Rechteck |
| Graphics.DrawGrid(x, y, w, h, cellW, cellH, color) | Gitter |
| Graphics.DrawPolygon(xs[], ys[], count, color) | Beliebiges konvexes Polygon |
Alpha-Blending
| Methode | Beschreibung |
|---|---|
| Graphics.SetPixelAlpha(x, y, color, alpha) | Pixel mit Alpha (0–255) |
| Graphics.FillRectAlpha(x, y, w, h, color, alpha) | Rechteck mit Alpha |
| Graphics.DrawTextAlpha(x, y, text, color, scale, alpha) | Text mit Alpha |
Texturen
// Texture erstellen und zeichnen
Texture tex = new Texture(64, 64, null);
// ... Pixel befüllen
Graphics.DrawTexture(tex, 200, 200);
// Texture freigeben (manuell nötig — kein GC)
// tex.Dispose();Beispiel
public override void OnFrame()
{
Graphics.FillScreen(Color.Black);
// HUD-Hintergrund
Graphics.FillRoundedRect(10, 10, 400, 60, 10, Color.RGB(30, 30, 60));
Graphics.DrawRoundedRect(10, 10, 400, 60, 10, Color.RGB(80, 80, 180));
// Score-Text
Graphics.DrawTextShadow(20, 25, "Score: " + _score.ToString(), Color.White, Color.Black, 2);
// Spieler
Graphics.FillCircle(_px, _py, 20, Color.Cyan);
Graphics.DrawCircle(_px, _py, 20, Color.White);
}