Swiftpack.co - Package - sunlubo/SwiftSDL2

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 SDL.initialize(flags: [.video])

let window = try Window(title: "Hello", width: 640, height: 480, flags: .resizable)
let renderer = try Renderer(window: window)

while let event = Events.wait(), event.type != EventType.quit.rawValue {
  let x = arc4random() % 640
  let y = arc4random() % 480
  let rect = Rect(x: Int(x), y: Int(y), w: 100, h: 50)

  try renderer.setDrawColor(.white)
  try renderer.clear()
  try renderer.drawRect(rect)
  try renderer.setDrawColor(.random)
  try renderer.fillRect(rect)
  renderer.present()
}

SDL.quit()

Github

link
Stars: 1
Help us keep the lights on

Dependencies

Used By

Total: 1

Releases

0.0.7 - Sep 7, 2018

0.0.6 - Aug 15, 2018

0.0.5 - Aug 12, 2018

0.0.3 - Aug 12, 2018

0.0.2 - Aug 12, 2018