ProductPromotion
Logo

Swift

made by https://0x3d.site

GitHub - STREGAsGate/Raylib: A Swift package for Raylib. Builds Raylib from source so no need to fiddle with libraries. Just add as a dependency in you game package and go!
A Swift package for Raylib. Builds Raylib from source so no need to fiddle with libraries. Just add as a dependency in you game package and go! - STREGAsGate/Raylib
Visit Site

GitHub - STREGAsGate/Raylib: A Swift package for Raylib. Builds Raylib from source so no need to fiddle with libraries. Just add as a dependency in you game package and go!

GitHub - STREGAsGate/Raylib: A Swift package for Raylib. Builds Raylib from source so no need to fiddle with libraries. Just add as a dependency in you game package and go!

Raylib for Swift

<img style="vertical-align:middle" src=https://aws1.discourse-cdn.com/swift/original/1X/0a90dde98a223f5841eeca49d89dc9f57592e8d6.png width="50"><img style="vertical-align:middle" src=https://www.raylib.com/common/img/raylib_logo.png width="50">

Windows macOS Linux

Twitter YouTube Reddit Discord

This package brings Raylib to Swift.

Raylib for Swift uses Swift's C interoperability and compiler to build Raylib from source code. Just add the package as a dependency (to your swift executable package) and start making games!

Requirements & Setup

On Windows and macOS you only need Swift. For Linux, see install required libraries.

Creating a new project

1. Create a Swift package for your project.

$ cd my/projects/folder/path
$ mkdir MyGame
$ cd MyGame
$ swift package init --type executable

2. Edit the newly created Package.swift to add Raylib to the dependencies array:

.package(url: "https://github.com/STREGAsGate/Raylib.git", branch: "master")

On Windows and macOS you only need Swift. For linux, see install required libraries.

Note: .branch("master") is required, you cannot use tags, commits, or versions. Swift doesn't allow unsafe build flags for specific versions and build flags are required to build Raylib, so you must use master at this time or you will get an error from SwiftPM.

3. Add the following to the static func main() in MyGame.swift.

    let screenWidth: Int32 = 800
    let screenHeight: Int32 = 450

    Raylib.initWindow(screenWidth, screenHeight, "MyGame")
    Raylib.setTargetFPS(30)
    let randomColors: [Color] = [.blue, .red, .green, .yellow, .darkBlue, .maroon, .magenta]
    var ballColor: Color = .maroon
    var ballPosition = Vector2(x: -100, y: -100)
    var previousBallPosition: Vector2
    while Raylib.windowShouldClose == false {
        // update
        previousBallPosition = ballPosition
        ballPosition = Raylib.getMousePosition()
        if Raylib.isMouseButtonDown(.left) {
            ballColor = randomColors.randomElement() ?? .black
        }
        let size = max(abs(ballPosition.x - previousBallPosition.x) + abs(ballPosition.y - previousBallPosition.y), 10)

        // draw
        Raylib.beginDrawing()
        Raylib.clearBackground(.rayWhite)
        Raylib.drawText("Hello, world!", 425, 25, 25, .darkGray)
        Raylib.drawCircleV(ballPosition, size, ballColor)
        Raylib.drawFPS(10, 10)
        Raylib.endDrawing()
    }
    Raylib.closeWindow()

About

Original Raylib global functions are now static members of the Raylib type.

Raylib.initWindow(screenWidth, screenheight, "My First Raylib Window!")

It's a goal of this project to have all the global functions available on their respective types as members.

As an example Image, now has new initializers.

let image = Image(color: .green, width: 256, height: 256)

Doing this for the entire API will increase discoverability and make Raylib for Swift a more Swifty experience.

More Resources
to explore the angular.

mail [email protected] to add your project or resources here ๐Ÿ”ฅ.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here ๐Ÿ”.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory