Chandram-Dutta/Iris
Iris: A minimal 2D game engine in Swift.
Philosophy
Iris provides the bare minimum to make games: a window, a game loop, drawing primitives, and input. No scenes, no ECS, no editor. You write code, you draw pixels.
Public API
Engine.run(game:) // Entry point
Game // Protocol: update() + draw()
Graphics // Drawing: clear, fillRect, drawImage, drawText
Color // RGBA (Float 0-1)
Image // Image.load("path.png")
Font // Font.system(size: 16)
Input // Input.shared.isKeyDown(.space)
Key // .left, .right, .up, .down, .w, .a, .s, .d, .space, .escape
DebugInfo // fps, deltaTime, frameNumberHello Game
import Iris
class MyGame: Game {
func update(deltaTime: TimeInterval, debug: DebugInfo) {
// game logic here
}
func draw(_ g: Graphics, debug: DebugInfo) {
g.clear(Color(r: 0.1, g: 0.1, b: 0.2))
g.fillRect(x: 100, y: 100, width: 50, height: 50, color: .red)
g.drawText("Hello Iris", x: 100, y: 200, font: Font.system(size: 24), color: .white)
}
}
@MainActor func main() {
Engine().run(game: MyGame())
}
main()Coordinate System
- Origin: top-left corner
- X: increases right
- Y: increases down
- Units: pixels
Error Handling
| Situation | Behavior | |-----------|----------| | Missing image file | Returns nil, logs warning | | Drawing outside screen | Allowed (GPU clips) | | Double-loading assets | Returns cached handle |
Requirements
- macOS (Metal)
- Swift 6.2+
Package Metadata
Repository: Chandram-Dutta/Iris
Stars: 13
Forks: 0
Open issues: 0
Default branch: main
Primary language: swift
License: MIT
README: README.md