SwiftSDL2

0.0.7

A Swift wrapper for the SDL2 API
sunlubo/SwiftSDL2

What's New

2018-09-07T23:46:17Z

SwiftSDL2

A Swift wrapper for the SDL2 API

Installation

You should install SDL2 before use this library, on macOS, you can:

brew install sdl2

Swift Package Manager

SwiftSDL2 primarily uses SwiftPM as its build tool, so we recommend using that as well. If you want to depend on SwiftFFmpeg in your own project, it's as simple as adding a dependencies clause to your Package.swift:

dependencies: [
    .package(url: "https://github.com/sunlubo/SwiftSDL2.git", from: "0.0.1")
]

Usage

import SwiftSDL2
import Darwin

try initSDL(flags: [.video, .audio])

let window = Window(title: "hello", width: 640, height: 480, flags: .resizable)
let renderer = Renderer(window: window)
let texture = Texture(renderer: renderer, format: .rgba8888, access: .target, width: 640, height: 480)

while true {
    if let event = Events.poll(), event.type == .quit {
        break
    }

    let x = arc4random() % 540
    let y = arc4random() % 430
    let rect = Rect(x: Int(x), y: Int(y), w: 100, h: 50)

    try renderer.setTarget(texture)
    try renderer.setDrawColor(Color(r: 0x00, g: 0x00, b: 0x00, a: 0x00))
    try renderer.clear()
    try renderer.drawRect(rect)
    try renderer.setDrawColor(Color(r: 0xFF, g: 0x00, b: 0x00, a: 0x00))
    try renderer.fillRect(rect)
    try renderer.setTarget(nil)
    try renderer.copy(texture: texture, srcRect: nil, dstRect: nil)
    renderer.present()
}

quitSDL()

Description

  • Swift Tools 4.0.0
View More Packages from this Author

Dependencies

Last updated: Wed Nov 09 2022 00:01:55 GMT-0500 (GMT-05:00)