SpriteKit + Playgrounds
With Swift, Apple introduced the wonderful concept of Playgrounds: little sandboxes of code that can be run independently from a project. They’re lightweight, small, and are able to show the results of your code live, line-by-line. This is great for simple experiments like learning about closures, tuples, or functions as variable types, but can be somewhat lacking when it comes to more media-rich forms of programming – like SpriteKit. Thankfully, Apple, too, has thought of this: enter XCPlayground
.
To set up a simple Playground with SpriteKit, copy and paste this code into a fresh Playground:
For this to work, it is necessary to have the Assistant Editor open (Cmd+Option+Enter, or the little double-circle icon in the toolbar). What’s really cool is that you can apply shaders, perform physics, run actions – anything you can do in a normal SpriteKit project. The only unknown for me is if it can detect touches through the mouse – that’s next on my to-do list – but I’m assuming not. If my hunch is right, there are still some things that are better left to a full project, but Playgrounds are now a much more powerful resource for trying out (simple) new things with SpriteKit – such as experimenting with SKConstraints
.