# SpriteKit for macOS and iOS is available

**URL:** <https://forum.xojo.com/t/spritekit-for-macos-and-ios-is-available/33278>\
**Category:** macOS\
**Created:** [September 6, 2016, 11:27pm UTC](https://forum.xojo.com/t/spritekit-for-macos-and-ios-is-available/33278 "2016-09-06T23:27:35Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ulrich\_Bogun](https://forum.xojo.com/user_avatar/forum.xojo.com/ulrich_bogun/32/1864_2.png) [@Ulrich\_Bogun](https://forum.xojo.com/u/Ulrich_Bogun)\
**Post date:** [September 6, 2016, 11:27pm UTC](https://forum.xojo.com/t/spritekit-for-macos-and-ios-is-available/33278/1 "2016-09-06T23:27:35Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![KevinW](https://forum.xojo.com/letter_avatar_proxy/v4/letter/k/94ad74/32.png) [@KevinW](https://forum.xojo.com/u/KevinW)\
**Post date:** [September 7, 2016, 10:52pm UTC](https://forum.xojo.com/t/spritekit-for-macos-and-ios-is-available/33278/2 "2016-09-07T22:52:02Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Ulrich\_Bogun](https://forum.xojo.com/user_avatar/forum.xojo.com/ulrich_bogun/32/1864_2.png) [@Ulrich\_Bogun](https://forum.xojo.com/u/Ulrich_Bogun)\
**Post date:** [September 8, 2016, 8:45am UTC](https://forum.xojo.com/t/spritekit-for-macos-and-ios-is-available/33278/3 "2016-09-08T08:45:40Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Ulrich\_Bogun](https://forum.xojo.com/user_avatar/forum.xojo.com/ulrich_bogun/32/1864_2.png) [@Ulrich\_Bogun](https://forum.xojo.com/u/Ulrich_Bogun)\
**Post date:** [September 8, 2016, 12:46pm UTC](https://forum.xojo.com/t/spritekit-for-macos-and-ios-is-available/33278/4 "2016-09-08T12:46:01Z")

</div>

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:  
[https://dl.dropboxusercontent.com/u/21200221/Xojo/SpriteKitRotate.mp4](https://dl.dropboxusercontent.com/u/21200221/Xojo/SpriteKitRotate.mp4)  
(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](https://developer.apple.com/library/prerelease/content/documentation/GraphicsAnimation/Conceptual/SpriteKit_PG/Introduction/Introduction.html#//apple_ref/doc/uid/TP40013043-CH1-SW1)

---

<div class="post-metadata">

**Author:** ![Ulrich\_Bogun](https://forum.xojo.com/user_avatar/forum.xojo.com/ulrich_bogun/32/1864_2.png) [@Ulrich\_Bogun](https://forum.xojo.com/u/Ulrich_Bogun)\
**Post date:** [September 10, 2016, 1:08pm UTC](https://forum.xojo.com/t/spritekit-for-macos-and-ios-is-available/33278/5 "2016-09-10T13:08:19Z")

</div>

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](https://dl.dropboxusercontent.com/u/21200221/Xojo/OSXLibSpriteKit.zip)

---

<div class="post-metadata">

**Author:** ![Ulrich\_Bogun](https://forum.xojo.com/user_avatar/forum.xojo.com/ulrich_bogun/32/1864_2.png) [@Ulrich\_Bogun](https://forum.xojo.com/u/Ulrich_Bogun)\
**Post date:** [September 10, 2016, 5:13pm UTC](https://forum.xojo.com/t/spritekit-for-macos-and-ios-is-available/33278/6 "2016-09-10T17:13:43Z")

</div>

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](https://github.com/UBogun/OSXLib/tree/SpriteKit). (Mind the branch!)

Please note OSXLib requires Joes ObjC blocks plugin: [https://xojo.io/f0e2dc7227f3](https://xojo.io/f0e2dc7227f3)

Heres the unsigned Mac build of the demo: [https://dl.dropboxusercontent.com/u/21200221/Xojo/OSXLibSpriteKit.zip](https://dl.dropboxusercontent.com/u/21200221/Xojo/OSXLibSpriteKit.zip)

Bugreports, requests and feedback highly appreciated!

---

<div class="post-metadata">

**Author:** ![ChristopheDV](https://forum.xojo.com/letter_avatar_proxy/v4/letter/c/59ef9b/32.png) [@ChristopheDV](https://forum.xojo.com/u/ChristopheDV)\
**Post date:** [September 10, 2016, 6:07pm UTC](https://forum.xojo.com/t/spritekit-for-macos-and-ios-is-available/33278/7 "2016-09-10T18:07:25Z")

</div>

thats pretty cool. Thank you for sharing Ulrich !

---

<div class="post-metadata">

**Author:** ![Ulrich\_Bogun](https://forum.xojo.com/user_avatar/forum.xojo.com/ulrich_bogun/32/1864_2.png) [@Ulrich\_Bogun](https://forum.xojo.com/u/Ulrich_Bogun)\
**Post date:** [September 10, 2016, 7:39pm UTC](https://forum.xojo.com/t/spritekit-for-macos-and-ios-is-available/33278/8 "2016-09-10T19:39:40Z")

</div>

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

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 \<[https://xojo.com/issue/43764](https://xojo.com/issue/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.

---

<div class="post-metadata">

**Author:** ![Ulrich\_Bogun](https://forum.xojo.com/user_avatar/forum.xojo.com/ulrich_bogun/32/1864_2.png) [@Ulrich\_Bogun](https://forum.xojo.com/u/Ulrich_Bogun)\
**Post date:** [September 11, 2016, 6:01pm UTC](https://forum.xojo.com/t/spritekit-for-macos-and-ios-is-available/33278/9 "2016-09-11T18:01:26Z")

</div>

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](https://github.com/UBogun/OSXLib)

Please note OSXLib requires Joes ObjC blocks plugin: [https://xojo.io/f0e2dc7227f3](https://xojo.io/f0e2dc7227f3)

Heres the unsigned Mac build of the demo: [https://dl.dropboxusercontent.com/u/21200221/Xojo/OSXLibSpriteKit.zip](https://dl.dropboxusercontent.com/u/21200221/Xojo/OSXLibSpriteKit.zip)

Bugreports, requests and feedback highly appreciated!

---

<div class="post-metadata">

**Author:** ![Ulrich\_Bogun](https://forum.xojo.com/user_avatar/forum.xojo.com/ulrich_bogun/32/1864_2.png) [@Ulrich\_Bogun](https://forum.xojo.com/u/Ulrich_Bogun)\
**Post date:** [September 16, 2016, 3:15pm UTC](https://forum.xojo.com/t/spritekit-for-macos-and-ios-is-available/33278/10 "2016-09-16T15:15:14Z")

</div>

OSXLib has moved as it has become part of a library combining both Apple systems:  
[https://github.com/UBogun/Xojo-AppleLib/](https://github.com/UBogun/Xojo-AppleLib/)

---

<div class="post-metadata">

**Author:** ![Ulrich\_Bogun](https://forum.xojo.com/user_avatar/forum.xojo.com/ulrich_bogun/32/1864_2.png) [@Ulrich\_Bogun](https://forum.xojo.com/u/Ulrich_Bogun)\
**Post date:** [September 26, 2016, 12:36pm UTC](https://forum.xojo.com/t/spritekit-for-macos-and-ios-is-available/33278/11 "2016-09-26T12:36:31Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Ulrich\_Bogun](https://forum.xojo.com/user_avatar/forum.xojo.com/ulrich_bogun/32/1864_2.png) [@Ulrich\_Bogun](https://forum.xojo.com/u/Ulrich_Bogun)\
**Post date:** [November 23, 2016, 4:40pm UTC](https://forum.xojo.com/t/spritekit-for-macos-and-ios-is-available/33278/12 "2016-11-23T16:40:16Z")

</div>

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](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.

---

<div class="post-metadata">

**Author:** ![Jens\_Knaack1](https://forum.xojo.com/user_avatar/forum.xojo.com/jens_knaack1/32/188_2.png) [@Jens\_Knaack1](https://forum.xojo.com/u/Jens_Knaack1)\
**Post date:** [November 23, 2016, 5:49pm UTC](https://forum.xojo.com/t/spritekit-for-macos-and-ios-is-available/33278/13 "2016-11-23T17:49:14Z")

</div>

I am interested (a lot).

---

<div class="post-metadata">

**Author:** ![KevinW](https://forum.xojo.com/letter_avatar_proxy/v4/letter/k/94ad74/32.png) [@KevinW](https://forum.xojo.com/u/KevinW)\
**Post date:** [November 23, 2016, 6:41pm UTC](https://forum.xojo.com/t/spritekit-for-macos-and-ios-is-available/33278/14 "2016-11-23T18:41:34Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Ulrich\_Bogun](https://forum.xojo.com/user_avatar/forum.xojo.com/ulrich_bogun/32/1864_2.png) [@Ulrich\_Bogun](https://forum.xojo.com/u/Ulrich_Bogun)\
**Post date:** [November 26, 2016, 10:33am UTC](https://forum.xojo.com/t/spritekit-for-macos-and-ios-is-available/33278/15 "2016-11-26T10:33:02Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Peter\_Fargo](https://forum.xojo.com/user_avatar/forum.xojo.com/peter_fargo/32/977_2.png) [@Peter\_Fargo](https://forum.xojo.com/u/Peter_Fargo)\
**Post date:** [November 26, 2016, 1:06pm UTC](https://forum.xojo.com/t/spritekit-for-macos-and-ios-is-available/33278/16 "2016-11-26T13:06:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Ulrich\_Bogun](https://forum.xojo.com/user_avatar/forum.xojo.com/ulrich_bogun/32/1864_2.png) [@Ulrich\_Bogun](https://forum.xojo.com/u/Ulrich_Bogun)\
**Post date:** [November 27, 2016, 6:19pm UTC](https://forum.xojo.com/t/spritekit-for-macos-and-ios-is-available/33278/17 "2016-11-27T18:19:58Z")

</div>

Taking into regard that I am basically the German Developer Evangelist, heres the German tutorial first:  
[https://xojoblog.me/2016/11/27/schneller-spielen/](https://xojoblog.me/2016/11/27/schneller-spielen/)

A translation will follow later.

---

<div class="post-metadata">

**Author:** ![Jens\_Knaack1](https://forum.xojo.com/user_avatar/forum.xojo.com/jens_knaack1/32/188_2.png) [@Jens\_Knaack1](https://forum.xojo.com/u/Jens_Knaack1)\
**Post date:** [November 27, 2016, 6:44pm UTC](https://forum.xojo.com/t/spritekit-for-macos-and-ios-is-available/33278/18 "2016-11-27T18:44:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Ulrich\_Bogun](https://forum.xojo.com/user_avatar/forum.xojo.com/ulrich_bogun/32/1864_2.png) [@Ulrich\_Bogun](https://forum.xojo.com/u/Ulrich_Bogun)\
**Post date:** [November 29, 2016, 1:42am UTC](https://forum.xojo.com/t/spritekit-for-macos-and-ios-is-available/33278/19 "2016-11-29T01:42:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [October 29, 2020, 6:27pm UTC](https://forum.xojo.com/t/spritekit-for-macos-and-ios-is-available/33278/20 "2020-10-29T18:27:03Z")

</div>


