SwiftGodotKit provides a way of embedding Godot into an existing Swift application and driving Godot from Swift, without having to use an extension. This is a companion to SwiftGodot which provides the API binding to the Godot API.
This branch contains the new embeddable system that is better suited
to be embedded into an existing iOS and Mac apps and allows either a
full game to be displayed, or indidivual parts in an app. This is
based on the new 4.4-based libgodot
patches that turn Godot into an
embeddable library.
If you are looking for the old version that only ran on MacOS, check
out the legacy
branch.
This module contains a TrivialSample
example code that shows both
how to embed a Godot-packaged game (PCK files) as well as embedding
Godot UI elements created programatically. This sample runs on MacOS.
For iOS, you need a proper container, you can look at the peer
SwiftGodotKitSamples
project which hosts this library and a sample
and deploys to iOS devices (there is no support for the iOS simulator,
as Godot does not really run on those).
Just reference this module from your Package.swift file or from Xcode.
A simple SwiftUI API is provided.
In the example below, in an existing iOS project type using SwiftUI, add a Godot PCK file to your project, and then call it like this:
import SwiftUI
import SwiftGodot
import SwiftGodotKit
struct ContentView: View {
@State var app = GodotApp(packFile: "game.pck")
var body: some View {
VStack {
Text("Game is below:")
GodotAppView()
.padding()
}
.environment(\.godotApp, app)
}
}
There can only be one GodotApp in your application, but you can reference different scenes from it.
Check out SwiftGodotKit and libgodot
as peers as well as a version
of Godot suitable to be used as a library:
git clone git@github.com:migueldeicaza/SwiftGodot
git clone git@github.com:migueldeicaza/SwiftGodotKit
git clone git@github.com:migueldeicaza/libgodot
Compile libgodot, this sample shows how I do this myself, but you can pass the flags that make sense for your scenarios:
cd libgodot
scons target=template_debug dev_build=yes library_type=shared_library debug_symbols=yes
The above will produce the binary that you want, then create an xcframework out of it, using the script in SwiftGodot (a peer to this repository):
cd ../SwiftGodot/scripts
sh -x make-libgodot.xcframework ../../SwiftGodot ../../libgodot /tmp/
Then you can reference that version of the libgodot.xcframework