I am building a SpriteKit based Interface Controller for a Watch page. The page has just a SpriteKite Scene embedded with interface builder. The scene renders and animates just fine. The hierarchy is:
App access An InterfaceController (One of many) SpriteKit Scene "brScene.sks" Graphic layout file "brScene.swift" Swift code to support Scene
The problem is accessing the Crown rotation in the brScene.swift. I need the Crown data to control movement of a sprite. This is a problem that has historically been addressed a few times back in the 2015-2016 timeframe for WatchOS 2 and 3, but the earlier solutions appear to all be broken now. Here is what I have tried:
import Foundation import SpriteKit import WatchKit class brScene: SKScene, SKPhysicsContactDelegate, WKCrownDelegate { class func newGameScene() -> brScene { //Load brScene.sks as SKScene guard let scene = SKScene(fileNamed: "brScene.sks") as? brScene else { print("Scene Load Failed") abort() } //fill window scene.scaleMode = .aspectFill let wkExtShared = WKExtension.shared() let crownSequencer = WKExtension.shared().sharedInterfaceController!.crownSequencer crownSequencer.delegate = self //** Can not assign or cast crownSequencer.focus() return scene }
The value of "self" at the failed delegate assignment is "AppChallenge_WatchKit_Extension.brScene". It has no delegate compatibility. Of note, the protocol addition to the brScene Class of WKCrownDelegate is rendered in black by Xcode, not in green like SKPhysicsContactDelegate. I believe I could probably make the page's InterfaceController the delegate for the crown and then post notifications back to the brScene.swift to move the sprite, but that seems highly inelegant and inefficient! What is going on? Any help would be appreciated!