• Register

Can you out-smart the alien space squid? Plucky space repair robot Space Bot Alpha finds his space ship has been invaded! Alpha can use his shields as long as he's on the ships power rails. Guide him to build walls and seal off the levels. But watch the wily alien! His touch is deadly when Alpha is out wall-building, and away from the power rails! Flash-bombs and energy powerups can help Alpha, explore the levels to find them before sealing it off. Once 75% of a level is sealed, the win is triggered with 1 star. But the more you seal off the more you're face to face with the evil space squid! Only top skill Space Bots can get 2 or 3 stars!

Post news Report RSS Swift for the Win

Since the future of Apple development seems to be the new Swift language, I had a look at working with Cocos2D using Swift.

Posted by on

Cocos2D is a lovely environment to code a 2D game for iOS. There's a lot of functionality there, and its ahead of SpriteKit for the fullness of what is offered. Also SpriteBuilder is a very nice tool now for building levels, setting up animations and generally managing your game data.

I wrote Space Bot Alpha in Objective-C, but my next game, and maybe even Space Bot Alpha 2 if it comes to that, will likely be in Swift.

But even thought pointing a browser at Cocos2d-iphone.org results in you finding yourself at Cocos2d-swift.org (via a redirect) it turns out that redirecting your development efforts with Cocos2D onto the Swift language is not so simple.


I found one person who had written a rough how-to using the "Mix-and-Match" technique which allows you to have the Cocos2D objective-c code just dumped in, cheek-by-jowl with your Swift based project code.

I prefer an approach which uses static libs to separate out the Cocos2D stuff from my code. Any debug switches and whatever else can apply just to that code. Building Cocos2D in Objective-C as a static library, and also its dependent Chipmunk physics, you can then replace the code that loads Cocos2Ds event loop and OpenGL canvas with Swift code that calls into the Cocos2D via a Swift bridging header.

Instructions and a template project are available on my GitHub project.

Cocos2D in Swift Hello World template

With an evening to play, I was able to get a basic re-usable hello world template up and working. From here its simple to load sprites and start hacking on the game using Swift.

To grab this just visit my github repo for Cocos2DInSwift.

Post a comment
Sign in or join with:

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.

Follow Report Profile
Icon
Space Bot Alpha
Platforms
Mac, iOS, Android
Contact
Send Message
Release date
Game watch
Follow
News
Tags
Dev Diary
Browse
News
New
Post news
Report
Report
Share
Related Games
Related Engines
cocos2d for iPhone
cocos2d for iPhone Zlib