How do I eliminate SKScene.scaleMode = .aspectFit cutting off on all 4 sides with rotation?

61 Views Asked by At

How do I eliminate SKScene.scaleMode = .aspectFit cutting off on all four sides with rotation?

I read elsewhere:

.aspectFit Scales the content to fill the size of the view. 
Some portion of the content may be clipped to fill the view’s bounds.

I call setupScene() from within override func viewDidLoad() {..}

In my func setupScene() {..} I call:

if let ourScene = SKScene(fileNamed: "aName") {

    ourScene.scaleMode = .aspectFit

}

And, indeed, a portion of the content is clipped to fill the view’s bounds. Resizing between Landscape and Portrait does happen as it should .. but the clipping on top and bottom happens.

I do note that there is zero clipping horizontally, but just vertically:

Portrait

Landscape

FWIW, I have used .aspectFill which renders a significant improvement, but clipping still occurs, albeit much less than with .aspectFit.

Finally, it is significant that my SKScenes are much taller than wide - and this may be the source of my problem.

Which begs the question, should I redesign my SKScenes to be square and not rectangular? I just do not know.

Any guidance as to how I can avoid cutoff and instead have the whole SKScene resized to the entire SKView, whether it's in Landscape or Portrait mode with zero cut off?

OR do I just elect AppleTV as the only destination because of the rectangular shape? I think this is an easy way out that just avoids having to find the real solution! .. so, no thanks!

1

There are 1 best solutions below

0
AudioBubble On

BINGO!!

  1. A Game which height is much greater than its width.

  2. If I allow .aspectFill to literally do its thing, cutoff will occur as already stated above. This makes sense because literally squeezing a tall height into Landscape mode would make all the enclosed Game Pieces super super tiny. Ugly to say the least.

  3. I literally thought of this "by accident" .. namely, when the user rotates their Device 90 degrees to Landscape, do rotate the Game Scene, but do not scrunch the size of all the enclosed Game Pieces and do not change their positions.

Keep these Game Pieces scaled and positioned as if they were still in Portrait mode even though the Device is physically in Landscape mode.

Analogy = when you cut down a tree, it goes from Portrait to Landscape, but the tree does not become shorter when on the ground.

So, go to Info and Custom iOS Target Properties and look for this:

Custom iOS Target Properties

ASAMOF, you can now eliminate any call to .aspectFill or .aspectFit

The rotated Scene

Remember this is a Game targeted for use with a Gamepad. Do you really want to be scrolling while your nifty Game Piece is trying to avoid hitting a barrier?

BINGO!