Skip to content

migueldeicaza/SwiftGodotKit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

95 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

New SwiftGodotKit

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.

Sample Code

MacOS Sample Code

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.

iOS Sample Code

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).

Using this

Just reference this module from your Package.swift file or from Xcode.

Sample

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.

Discussions

You can join our Discussions on GitHub or the #swiftgodotkit channel on the Swift on Godot Slack server.

Sausage Making Details

Check out SwiftGodotKit and libgodot as peers as well as a version of Godot suitable to be used as a library:

git clone [email protected]:migueldeicaza/SwiftGodot
git clone [email protected]:migueldeicaza/SwiftGodotKit
git clone [email protected]:migueldeicaza/libgodot

For LibGodot, you want to use the libgodot_44_stable branch 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

About

Embed Godot into Swift apps

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 5