SpriteView > WatchOS 7

Ciao,
I would like to use SpriteKit within SwiftUI on WatchOS 7.
Which works fabulously on iOS 14 via SpriteView(scene: scene)

But when I use the same code from iOS 14:


import SwiftUI
import SpriteKit

class GameScene: SKScene {
override func didMove(to view: SKView) {
physicsBody = SKPhysicsBody(edgeLoopFrom: frame)
    }
}

SKView throws an error. And now I'm not sure how to use SpiteKit within SwiftUI on watchOS 7.

Before with WatchKit. I used WKInterfaceSKScene... via Storyboard.

I would love to get some some suggestions what I've been missing.

Grazie
Vasco
SKView is not available in watchOS, so there is no didMove(to view:) method in watchOS.

On watchOS, it is recommended that you use sceneDidLoad() to perform any one-time setup of your scene when the scene is loaded!
thanks.
I found that out too.

But my problem is that I can't get a SpriteKit scene loaded on watchOS 7 using SwiftUI

You can use SKScene on WatchOS, but curiously SKScene lacks didMove(..), so only sceneDidLoad() is available. https://developer.apple.com/documentation/spritekit/skscene/1519607-didmove

I am having trouble with using SwiftUI as the wrapper and adding in gestures. It seems to lose the reference to the SKScene when SwiftUI does a full view update.

I wanted to leave this here if anyone else is having trouble with showing a SKScene on WatchOS. There definitely are gaps that I feel make SwiftUI with SpriteKit untenable for real development.

import SwiftUI
import SpriteKit

struct GameView: View {struct GameView: View {
    var body: some View {
        SpriteView(scene: gameScene)
            .ignoresSafeArea()
    }

    var gameScene: GameScene {
        let scene = GameScene(size: WKInterfaceDevice.current().screenBounds.size, something: 1)
        scene.scaleMode = .fill
        return scene
    }
}

struct GameView_Previews: PreviewProvider {
    static var previews: some View {
        GameView()
    }
}

 use sceneDidLoad()  . But how to handle the touch event in GameScene (SKScene) when use SpriteKit within SwiftUI on WatchOS ?

SpriteView > WatchOS 7
 
 
Q