0

I just bought the Apple Watch and I want to create a super simple game for it. It is simple enough to only use monochrome color scheme, but advanced enough to have an object moving in real-time.

I am trying to figure out how to position an object on my Apple Watch with Watch OS 2.

I want to place my object somewhere on the screen (anywhere I'd like to) but there are absolutely no way to do that, I think.

But, in the following library: https://github.com/shu223/watchOS-2-Sampler the developer can actually animate the alignment of the image so I guess that itself suggests it should be possible to somehow specify a point of where to position an object. And the animation is pretty smooth as well.

I have tried to generate frames on-the-fly CGContext which uses Quartz 2D, but it's way too slow and the app on my Apple Watch just crashes.

I don't necessarily think that the watch itself is too weak, but some clever programming should solve my problem, but I just cant figure out how to do it.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
vaid
  • 1,390
  • 12
  • 33

2 Answers2

0

As you already said there is no way to directly position an WKInterfaceObject on your watch. You can change the alignment of an object but that leaves exactly 3 positions: left, center and right. Probably not enough for your game.

What you could do: You can set a background image on a WKInterfaceGroup. So you could draw your game objects into an UIImage and set that as background image of that group. That background images can also be animated. So maybe you can draw the movement of your game object into several UIImages and then set those as animated background image.

joern
  • 27,354
  • 7
  • 90
  • 105
  • I've tried everything that you're suggesting several days ago, but they all result in pretty bad performance. Alignment will, as you said, result in 3 possible positions. Drawing to a `UIImage` will result in very bad performance as the physical watch does not seem to like RealTime rendering with `CGConext`. I've even asked a question on Apple Dev Forum about this. And animating using several generated `UIImage` kind of work, but the app crashes once it reaches a certain level of memory usage. – vaid Oct 24 '15 at 17:53
0

One way that I have found to have a little more control over where a WKInterfaceObject is on the screen is to add it to a parent WKInterfaceGroup, and center your item (vertically and/or horizontally depending on how you want to move it). Then you can tweak the group's relative height / width (setRelativeHeight and setRelativeWidth) and it's alignment (setVerticalAlignment and setHorizontalAlignment) to get your item positioned where you want.

This doesn't give you the ability to tweak frames or give the item a particular coordinate, but it does give you the ability to programmatically move a WKInterfaceObject anywhere on the screen.

For example if you want your object in the exact center of the screen vertically, you leave the group's relative height to its container as 1, with your item centered. To get the object at 40% from the top, you can change the group's relative height to 0.8 and it's alignment to .Top. If you want it 60% from the top, the relative height would still be 0.8, but the group's vertical alignment should be .Bottom etc.

I know this is kind of a confusing way to have to accomplish this, but this worked for me in getting items positioned exactly how I wanted.

Marcus
  • 839
  • 8
  • 14