SpriteKit for macOS and iOS is available

During the next days, I’ll finish the first (incomplete) Xojo implementation of SpriteKit for macOS.
If you don’t know what it is: It’s Apples framework for 2D game and physics simulation development.
It runs in 64 bit only, but it brings astonishing simplicity to sprite handling, and it is optimized for Metal, Apple’s even-faster-than-OpenGL-GPU interface.
You should even be able to create complex sprites and scenes in XCode and use them directly in your Xojo app bundle.
And, once I got the time to clean up iOSLib, the apps should run with only a few modifications on iOS too.

That’s where I’d love to have help: I might be able to build the code and document it, but I don’t have the time to explore every feature of it.
It would be great to have some daring testers to get feedback on where things do not work well - or need more convenience methods for a more Xojo-like feeling.

If you are interested in helping to make Xojo a better platform for game development too, please send me a PM or reply here.
Thanks a lot!

I’d like to give it a shot on iOS. I have a game that’s been sitting on the shelf for a while with minimal functionality. It just uses canvas and it get’s kind of slow when about 20+ sprites are on the screen. Not sure when I would have time to get back on it and test though. I wouldn’t mind having it run on Mac as well, but that would be secondary to iOS.

Let us know if you get iOS up and running and I’ll see if I can find some time to update it. It would be great if I could get it to run faster as it’s one of those games that gets more hectic the further you go. It’s kind of important that it remains responsive in the later levels.

Great, Kevin, thanks a lot! I started a clean copy of iOSLib with separated frameworks and will re-integrate SpriteKit and the necessary core classes from the macOS version once I rebuilt all the SK classes. Don’t know how long it will take, but I’ll send you a note here. 20 sprites or so should be no problem, in theory a lot more (and you can even employ EmitterNodes for stars, smoke, whatever), and it would be nice to find out if it performs ok. Expect it to look lame in Simulator. SpriteKit is emulated on the Mac CPU.

Just a quick intro for those who replied:
First you’ll need a control of class OSXLibSKView (or iOSLibSKView, for that case).
Besides most of the Responder and View events (Klick, Touch and Gestures are supported), it features 5 main events that fire consecutively once a scene is presented where you can attach your game code:

UpdateScene (starts before any automatic calculations are applied)
DidEvaluateActions (actions attached to nodes have been processed)
DidSimulatePhysics (you name it!)
DidApplyConstraints (Yes, a bit like iOS autolayout: Constraints can hold nodes in a certain distance related to each other or change their orientation in relation to their positions)
FinishedSceneUpdate (everything automatic has been done)

EDIT: And you don’t have to use them. You can create a game with Actions only and leave the events untouched as well.

How often these events are called depends on the AppleSKView’s preferredFPS property. Usually it tries to reach 60 FPS.
The AppleSKView is the object itself, OSXLibSKView is just a control container for it. You access if via OSXLibSKView.AppleObject (and I want to forward conversions to Xojo classes and convenience methods to the container later).

Like written above, a SKView is used to present a scene. A scene has a certain size that you define when creating one, and it can contain different kinds of SKNodes. These are the basic building blocks, and they come in different flavors: SpriteNodes to draw sprites, LabelNodes for Text, AudioNodes for sound sources bound to a certain spot of the scene, CameraNodes, EmitterNodes for special mass effects and so on. A scene itself is a node too.

You add nodes with their AddChild method and can build tree structures if you like. Nodes can be connected by the use of Constraints, ReachConstraints (that help to define the movement of connections like ankles), and you can attach PhysicsBodies to them to make them subject to gravity and different kinds of forces.
These PhysicsBodies can be used to build joints of different kinds between them, from the PhysicsWorld property of the scene.

And then you have a myriad of Actions that you can attach to these nodes, and which you can group, play in order or call another block once they finished. PhysicsBodies are used to detect collisions too. For these, you have different kinds of 32Bit bitmaps you can use to define which type(s) a body belongs to and to which type(s) of other objects it should react. Contacts are forwarded to the control as events which feature a PhysicsContact object that tells you which two objects collided at which point with which impact.

As a very short intro:

Sub Shown() Handles Shown me.AppleObject.ShowsFPS = true dim scene as new AppleSKScene (me.AppleObject.Frame.size_) scene.BackgroundColor = AppleColor.FromColor (&cCEFFE100) me.AppleObject.Present(scene) dim label as new AppleSKLabelNode("OSXLib SpriteKit", "Helvetica-Neue") label.FontColor = AppleColor.FromColor(&c0E77B200) label.FontSize = 80 label.Position = scene.Frame.Center label.PhysicsBody = new AppleSKPhysicsBody (label) label.PhysicsBody.Mass = 0.01 scene.PhysicsWorld.Gravity = FoundationFrameWork.CGMakeVector(0.0, -0.1) scene.AddChild label label.RunAction(AppleSKAction.Group(AppleSKAction.ApplyImpulse(FoundationFrameWork.CGMakeVector (0, 0.5), 4), AppleSKAction.ApplyTorque(0.03, 4))) End Sub

in the Shown event of an OSXLibSKView shows this:
(completely smooth in reality, stops only due to the screen recording software)

And Apple explains a lot more: https://developer.apple.com/library/prerelease/content/documentation/GraphicsAnimation/Conceptual/SpriteKit_PG/Introduction/Introduction.html#//apple_ref/doc/uid/TP40013043-CH1-SW1

I extended the small demo a bit and am close to completing the first release of the framework. Only very few (and very specialized) classes are missing.
You can click on the label now to give it an impulse. When the label collides with the border of the view, I play a SoundAction (which should be saved instead of recreated each time because Apple forgot to close the soundfile … it leaks a bit. For this demo it’s ok, I guess.) All the set-up and event handling take about 30 lines of code total.

Here’s the unsigned Mac app: https://dl.dropboxusercontent.com/u/21200221/Xojo/OSXLibSpriteKit.zip

It’s fairly complete now (mainly Effectnodes are missing because I have to port CIFilter first). You can find it under https://github.com/UBogun/OSXLib/tree/SpriteKit. (Mind the branch!)

Please note OSXLib requires Joe’s ObjC blocks plugin: https://xojo.io/f0e2dc7227f3

Here’s the unsigned Mac build of the demo: https://dl.dropboxusercontent.com/u/21200221/Xojo/OSXLibSpriteKit.zip

Bugreports, requests and feedback highly appreciated!

thats pretty cool. Thank you for sharing Ulrich !

You’re welcome, Christoph!
I should add that while basically OSXLib is free to use (and free to contribute, too), for SpriteKit and later SceneKit the same license restriction like for iOSLib SpriteKit applies: I’d like to get a license of any game created with it. :smiley:

I’ll move SpriteKit to the main branch later (so that this gets all the other updates too), but while CoreBluetooth is still not accessible under 64Bit the main branch will be a bit clumsy: You’d have to remove CB. Therefore the separate branch. I’ll probably better move CB out of main later until feedback://showreport?report_id=43764 is fixed.

Oh, and one more thing: There is no separate documentation (yet), but every method and property should have a Xojo description tag. And besides the events, the OSXLibSKViewer has no convenience methods for addressing the real view, so (currently) you need to use its AppleObject As AppleSKView to address all the features – except the events which are forwarded to the OSXLibSKView via Addhandler automatically. Which I’d recommend in this case anyway, because conversion to and from normal Xojo objects would consume quite some time.
I’d be especially interested if loading a SKS file from XCode’s SpriteKit Builder works. Haven’t tested yet. But it did so in iOSLib, and you could address the nodes via the names you gave them in XCode.

After I tackled CoreBluetooth on 64Bit:
– EffectNode added. Now missing mostly the macOS 10.12 new warp features only.
– Deleted the branch. You find SpriteKit now under the main branch: https://github.com/UBogun/OSXLib

Please note OSXLib requires Joe’s ObjC blocks plugin: https://xojo.io/f0e2dc7227f3

Here’s the unsigned Mac build of the demo: https://dl.dropboxusercontent.com/u/21200221/Xojo/OSXLibSpriteKit.zip

Bugreports, requests and feedback highly appreciated!

OSXLib has moved as it has become part of a library combining both Apple systems:

This is especially for @Kevin Windham :
I added SpriteKit to iOSLib (again) now too. It shares its code with OSXLib, only the custom control is an iOSLibSKView in this case. You’ll find a demo project exactly resembling the OSXLib SK demo in the repository.

Question: Is someone interested in a short SpriteKit games tutorial?
I took the files from this excellent tutorial: https://www.raywenderlich.com/118225/introduction-sprite-kit-scene-editor, imported them into macLib, tweaked a few things and had the demo running in less than an hour on a Mac (although the SK files were designed for iOS).
So I can confirm you can use Xcode’s SpriteKit scene editor for your Xojo game projects. If someone should be interested, I would write up how to.

I am interested (a lot).

That would be way cool. Unfortunately I haven’t had any time to work on my game recently due to lots of external factors, but that might help me get up to speed much quicker on converting it over to SpriteKit.

Thanks a lot for your replies, and sorry for the delayed answer! I just received written consent to use the tutorial footage from RayWenderlich, so I’ll set up a small tutorial next week. BTW, if you are interested in game design: RayWenderlich offers a 50% BF discount on their store too. I just grabbed their game design books which are brilliant. Their code can be translated almost literally line by line into Xojo.

+1 on RayWenderlich. Very good books & tutorials. I used one of their Swift tutorials as a template for a GameKit in Xojo. I wanted SpriteKit type functionality but cross platform. It worked out great but I need to update it to OpenGL as the native drawing can only take you so far. Ulrich’s implementation should be great for MacOS/iOS.

Taking into regard that I am basically the German Developer Evangelist, here’s the German tutorial first:

A translation will follow later.

Or you could think about learning German. To read what has been written by Ulrich some days earlier would be worth the little time and effort.

While I doubt that my tiny tutorial would justify the effort of learning German, you might call it a nice coincidence that WordPress just published a Google Translate widget which is now accessible at the bottom of my blog’s sidebar. In some cases, you might be able to figure out what I meant. In every case, it will give you a good laugh.