Better Programming

Advice for programmers.

Follow publication

Member-only story

7 Ways to Link SwiftUI Views to SpriteKit Scene

Mark Lucking
Better Programming
Published in
4 min readAug 3, 2021
Paperclips
Photo by Tamanna Rumee on Unsplash

I was playing around with SpriteKit, and it occurred to me that it might be a good exercise to remind myself of how many different ways I could link my SwiftUI code with my SpriteKit scene/class. I don’t present these in any order, preference, or recommendation; I show them in the order that they came into my head more or less.

The Brief

I am running a SpriteKit scene within a SwiftUI app, and I want to be able to control a sprite directly using a SwiftUI element, a button in this case. Join me to see how many ways I can cook up — to do just that.

Let’s begin with the basic code. Now I present both structs/classes in the same file, although you will want to have them defined in separate ones really.

With the end goal to come up with as many different ways to do this as I can, the blue text jump is a SwiftUI button. The rabbit is a SKSpriteNode inside a scene hosted by my SwiftUI…

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Mark Lucking
Mark Lucking

Written by Mark Lucking

Coding for 35+ years, enjoying using and learning Swift/iOS development. Writer @ Better Programming, @The StartUp, @Mac O’Clock, Level Up Coding & More

Write a response