SpriteKit scaling problems and iPad Support

Hey (:


I'm currently working on a SpriteKit Playground (iOS Target), and everything works great on the Mac. But problems arose when I tryied it on my iPad. Without setting a scale mode, the scene get's completly distored. That's why I set the following ScaleMode:


gameScene.scaleMode = SKSceneScaleMode.aspectFit


But this comes with it's own problems. Since my scene is squared, I now get big black bars on top and on bottom of the scene. Setting a background color to the SKView doesn't change that.

And the far bigger problem is, that the aspectFit completly messes with my TapRecognizer. I check if a touch happend in the scen via:


gameScene.contains(location)


But, the touches that are recognized as contained in the gameScene are partly in these black bars, and only partly in the displayed scene. Clicking in the bottom quater of the displayed scene is not even recognized as clicks within the gameScene. I calculated some stuff and tried to add an offset, but it is always is off several pixels.


So, I now have several Questions:
1. Any idea how to get rid of those black bars?

2. Any idea how to fix the tap recognizer problem?

3. Do we have to support the iPad? I mean, these problems didn't arouse on the Mac, it works perfectly there. This doesn't mean that I don't wanna support the iPad, but if it is unneccessary, then I will spend my time in improving on the Playground iteself, rather than fixing stuff on the iPad


(PS: The whole code works great as iOS App. The TapRecognizer bug and black bars only appear within the Playground app).

Replies

So, if anyone is interested: I have a "solution" for the case that you don't resize the iPad screen while the playground is executing. Here is how it goes:


After setting your view as PlaygroundPage.current.liveView, make an UIView.animate with an dealy and duration of about 0.01. As animation, do something that the user can't see, like setting the alpha from a view from 0.0 to 0.01. Now, when the completion handler is entered, you will get the correct size of the view that you did set as your liveView, simply by calling yourView.frame.size. That's where you can set up your gesture recognizers and your SKScene.


I know, it's an ugly hack, but it works. Keep in mind, as soon as you resize the running playground in the app, the black bars reappear and the recognizer will stop working correctly. Still haven't found a solution for that - Constraints also don't solve that.


Best,
Klemens

Just wanted to add here that I have been experiencing the same problem with SpriteKit. As apparent in the source code for several of Apple's playground books, there is a way to accomplish layout resizing using a compiled storybaord in a .storyboardc file. I have seen a few snippets that used programmatic constraints as well. The problem here is that there are no examples or documentation for creating dynamic layouts at all. I'd love to hear if anyone has seen anything along these lines on the internet...


Joel