Hello! In my article I want to talk about the experience of developing games for the Apple Watch. The game is called Space Beaver (Beaver and Space). It is also available on iphone. But in this article there will be a story about the watch version. The source code is
here .
Idea:The essence of the game is a quick swap depending on the direction of the arrows. If the blocks with arrows filled the entire playing field, the player lost.
')
After creating the game on the iphone, I decided to try porting it to the Apple Watch. But unfortunately it turned out that the used engine (Unity) does not support this platform - that is, you cannot make the game assembly for the clock (
unity roadmap ). There are third-party plug-ins for interaction between the game on the iphone and the application on the Apple Watch (
watchkit-unity ), but this is not what I needed.
Development:In 2016, Apple released SpriteKit for Apple Watch and added support for Game Center (
video ). And I decided to take advantage of this. He wrote the game on swift. Tested on the simulator, as there is no iphone or Apple Watch.
To begin with, I made a new project (Single View Application). Then added a new target (WatchOS -> Game App).

Two folders are added to the project. The first folder with the main
storyboard . It contains a game controller with a SpriteKit scene and additional menu, game center, and game end controllers. Also in the first folder are the icons and resources for the storyboard. The second folder (Extension) contains the source code and resources for the SpriteKit scene.
Began development from the main menu of the
main menu .

Initially, I wanted to do the whole UI on SpriteKit. But I did not find a convenient way to use the buttons in SpriteKit. Therefore, I decided to make all the menus on the standard items for WatchKit.
I wanted to connect social networks (login on VK and Facebook) and repost records, but it turned out that there is no easy way to do this. The ios has a
Social Framework , but it does not yet support WatchOS. Therefore, I decided to postpone until better times.
Then he took up the creation of the screen of the game itself (
MainGameController and
the SpriteKit scene ).

Here everything was standard for SpriteKit. The update method executes a code for moving blocks and removing them depending on the player’s gestures. By the way, gestures I used the standard replicators. From the library to the storyboard I dragged and indicated events. Animated wrong gestures with SKAction.
Added training - also used
SKAction animations.
Added music using the SKAudioNode class. By the way, music is controlled using SKAction.play () and SKAction.stop ().
Added haptic feedback effects to the game. Effects are used when losing and with the wrong gesture. Used the WKInterfaceDevice.current (). Play (.)
Function (
WKInterfaceDevice ).
Added a pause when using force touch on the main game screen. Used element
WKInterfaceMenu . I tried to use my icons instead of icons, but only alpha is taken from the image there. You can also change the background color.

After creating the game screen, proceeded to the game completion popup window (
GameEndController ).
Here everything is standard for WatchKit. When I lose to the top of the stack, I throw the loss controller, when I press the replay button, I remove the upper controller, on the back arrow button, we go to the main menu screen. As I wrote above, I wanted to add a button to share the record in social networks, but I did not find a convenient way.

Then he began to fasten the game center (
GameCenterWatchController ). The epl has a
video , but it tells about step-by-step multiplayer and says nothing about how to connect the Leaderboard to the game. So I decided to use the controller for the tables (WKInterfaceTable). Received records through the GameKitHelper.sharedInstance.getPlayerScores () method. By the way, while testing the game center is not supported on the simulator (the GameKit library is not imported). Therefore, I did not test this function as normal.
There were several problems with the release:1) I made the game for hours separately from the main game project. When building a game for ios, unity (5.5.1) creates an Xcode project. I added a target for Apple Watch to this project. But it was impossible to archive (Archive) the assembly in any way. I played a little with the project build settings: set for the project (Unity-Phone) Build Settings: Supported Platforms - iOS, Architectures - Standard architectures. For TARGETS: BeaverSpace: Supported Platforms - iOS; Architectures - Standard architectures; SpaceBeaverWatch: Supported Platforms - watchOS, Architectures - Standard architectures; SpaceBeaverWatch Extension: Supported Platforms - watchOS, Architectures - Standard architectures.

2) The game did not go through the upgrade from the first time. I added a target for the Apple Watch to the project and copied the files from another project into it. But I forgot to change the modules in each controller of the main storyboard for the clock. After the fix, everything was fine.
Finally:I spent 2 weeks on the game for Apple Watch, but at the same time I made the basic version on ios for 4 months in my spare time. In general, I really liked the design for watches, despite the problems and inconveniences. We were pleased that Apple did SpriteKit support for WatchOS. I plan to promote the game for hours in thematic groups of VC and with the main game. Also added keywords related to Apple Watch. While at 541 place on the request of “apple watch game” in the US.
Thank you all for your attention.
→ The source code of the Space Beaver game (Beaver and Cosmos) is
here .