So as of watchOS 3.0 you are now able to get the rotation of the digital crown. I managed to use the crownDidRotate function in an InterfaceController. But I can't get the rotation of the crown from inside a SKScene Class. Can anybody help me with this I'm pretty lost right now? Thanks.
To get those crownDidRotate
calls in your interface controller, you had to adopt the WKCrownDelegate
protocol in your interface controller, and set your interface controller as the delegate
of its crownSequencer
.
To get crownDidRotate
calls in some other class, adopt the WKCrownDelegate
protocol in that class, and set an instance of that class as the delegate
of your interface controller's crownSequencer
.
Presumably you already have some code like this to set up your SpriteKit scene:
class InterfaceController: WKInterfaceController {
@IBOutlet var spriteGizmo: WKInterfaceSKScene!
override func awake(withContext context: AnyObject?) {
super.awake(withContext: context)
let scene = MyScene(fileNamed: "MyScene")
spriteGizmo.presentScene(MyScene(fileNamed: "MyScene"))
}
}
If you've declared WKCrownDelegate
conformance in your MyScene
class, just add a line to set it as the delegate of the interface controller's crown sequencer:
let scene = MyScene(fileNamed: "MyScene")
spriteGizmo.presentScene(MyScene(fileNamed: "MyScene"))
crownSequencer.delegate = scene
(Alternatively, you may set your WKInterfaceSKScene
's scene in the Storyboard. In that case, you can still reference the WKInterfaceSKScene
from your interface controller with an IBOutlet
. Then in awake(withContext:)
, you can access the scene through that outlet and set it as the crown delegate.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With