Skip to content

Instantly share code, notes, and snippets.

@lalabuy948
Last active November 9, 2019 22:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lalabuy948/5562cb4c9a861499dbfa283948eb92c9 to your computer and use it in GitHub Desktop.
Save lalabuy948/5562cb4c9a861499dbfa283948eb92c9 to your computer and use it in GitHub Desktop.
Standalone WatchOS game setup

How to setup standalone game for WatchOS

  • Create app for WatchOS using Xcode 11
  • Create files attached to this gist
  • Folow next step and you r gucci

Initial gameScene setup

Add SpriteKit Scene to interface.storyboard and put check box on fullscreen
import WatchKit
import Foundation
class GameController: WKInterfaceController, WKCrownDelegate {
// Add SpriteKit outlet here
@IBOutlet weak var skInterface: WKInterfaceSKScene!
var gameScene:GameScene!
override func awake(withContext context: Any?) {
super.awake(withContext: context)
// start listening to crown
crownSequencer.delegate = self
crownSequencer.focus()
// Load the SKScene from 'GameScene.sks'
if let scene = GameScene(fileNamed: "GameScene") {
gameScene = scene
// Set the scale mode to scale to fit the window
scene.scaleMode = .aspectFill
// Present the scene
self.skInterface.presentScene(scene)
// Use a value that will maintain a consistent frame rate
self.skInterface.preferredFramesPerSecond = 30
}
}
override func willActivate() {
// This method is called when watch view controller is about to be visible to user
super.willActivate()
}
override func didDeactivate() {
// This method is called when watch view controller is no longer visible
super.didDeactivate()
}
// @IBAction func swipedRight(_ sender: Any) {
// WKInterfaceController.reloadRootPageControllers(
// withNames: ["MainMenu"], contexts: [], orientation: .horizontal, pageIndex: 0
// )
// self.pushController(withName: "MainMenu", context: nil)
// }
}
import SpriteKit
class GameScene: SKScene, SKPhysicsContactDelegate {
override func sceneDidLoad() {
}
override func update(_ currentTime: TimeInterval) {
// Called before each frame is rendered
}
}
import WatchKit
import Foundation
class InterfaceController: WKInterfaceController {
override func awake(withContext context: Any?) {
super.awake(withContext: context)
// Configure interface objects here.
}
override func willActivate() {
// This method is called when watch view controller is about to be visible to user
super.willActivate()
}
override func didDeactivate() {
// This method is called when watch view controller is no longer visible
super.didDeactivate()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment