Last active
June 17, 2019 08:32
-
-
Save lalabuy948/87c4491f066ced98162b554ab0a53d7f to your computer and use it in GitHub Desktop.
Crown rotate event for WatchKit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import WatchKit | |
import Foundation | |
class InterfaceController: WKInterfaceController, WKCrownDelegate { | |
@IBOutlet var skInterface: WKInterfaceSKScene! | |
override func awake(withContext context: Any?) { | |
super.awake(withContext: context) | |
// start listening to crown | |
crownSequencer.delegate = self | |
crownSequencer.focus() | |
... | |
} | |
func crownDidRotate(_ crownSequencer: WKCrownSequencer?, rotationalDelta: Double) { | |
// convert crown rotation to CGFloat | |
let step = NSNumber.init(value: rotationalDelta * 20.0).floatValue | |
let cgStep = CGFloat(step) | |
// log whats happened | |
print("Crown: \(cgStep)") | |
gameScene.doSomething(amountX: cgStep, amountY: 0) | |
} | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment