Discussion: Adding open source SWIFT to Cocos2d-x?

Apple just announced that they will be open sourcing SWIFT 2 in the fall, with prebuilt libraries for iOS, Mac, and Linux. If Cocos-X integrated this, would it be more like Lua binding on top of the C++ version, or more of a separate version like Cocos2d-JS? I know there is already a Cocos2d-Swift project, formerly Cocos2d-iPhone, but I want to stay with X as I am excited about the 3D stuff.

Thoughts?

This is great news, Swift is an awesome language. A while back I wrote some Swift bindings for Cocos2d-x, I guess I will need to dust them off and finish them :smile:

This is great. It’ll be interesting to see how good the support is across the platforms once it’s available. I wonder if there’s a good way to enable bindings across more languages (like Swift) without a ton of additional work. So @mannewalis curious how much work you’ve found adding Swift bindings.

It’ll be interesting to see how cocos2d-spritebuilder moves forward with this news as well.

kudos! that was swift… :smile:

@stevetranby Swift is unique in that is is integrated extremely well with objective-c so it didn’t take much time at all. I was building a demo game in swift at the time, learning swift, and building the bindings as I needed them. The state it is in now is just the bindings I needed for the sample Swift game I worked on.

I don’t think we are quite out of the woods yet though. The platforms Apple decided to support is very telling. No mention of Android, and while that may be strategic, I think that Linux already has an objective-c runtime working, whereas Android does not, at least an open source one.

Apple was just being indirect. They are open-sourcing Swift and letting the community port it to Windows and Android…

2 Likes

Also: Swift 3.0 https://github.com/apple/swift-evolution
Portability: Make Swift available on other platforms and ensure that one can write portable Swift code that works properly on all of those platforms.
@mannewalis By the way: what do you guys think about this https://www.kickstarter.com/projects/1455832115/cocos2d-pureswift ?

1 Like

Swift 3.0 is really more like the actual open source release, unfortunately. It’s great that they published what they did and it’ll allow the community to help them get to 3.0 more quickly (hopefully with windows support). In reality it’s very much similar to .Net and the JVM in the sense that there’s a core feature set that works across platforms and then there are either cross-platform UI layers that don’t look great or you write platform-specific code for all the view components of your app. The performance should be closer to C++ (if not better in some areas due to specific optimizations)

I’d be interested in Swift as a scripting language for games, or even used with cocos2d-x in the same manner as Lua where you write most or all of the game. But I do feel like Lua or Javascript offer better scripting characteristics. I’m a beta tester at heart and play around with lots of languages, so I’m curious to see where things go from here.

It’s always a tough thing when you can see envision something like PureSwift (or open Swift) being a great game engine (or language/platform) 5 years from now, but you don’t see it being any better than cocos2d-x was for the first 3 years (ie: not that great). Probably smart to keep an eye on, play around to learn it, and experiment with simple apps.

:slight_smile:

I have begun work on this and have some basic unit tests running. I would love to get feedback from the community. The idea is to add a C API, and Swift can call into that.

1 Like

Here is my pull request for a C API for Cocos2D

+1

Definitely interesting to check out your branch. A ‘C’ API is the direction needed for new compiled language bindings. A Rustlang version could be written close behind the swift version. Also, Haxe support could possibly be available with this, or at least a much easier path to using haxe for some of the code. And other languages.

Are you auto-generating any of the code that exists in the PR? I’d hope so, but maybe it’s been just as quick copy/paste or using snippets or similar. It’d be smart for porting it alongside version updates and especially v4.x.

Curious, are you coming from cocos2d-iphone/spritebuilder/etc?

I’d like to see a separate PR for the C API with another having the PureSwift API? Thoughts.

Edit: added some extra comments

cocos2d-objc is actually being rewritten in Swift, in case somebody really want a Swift version of cocos2d.

1 Like