SpriteKit camera is not centred with aspectFit - ios

My scene is set to be .AspectFit. I have camera node in scene center and it is connected. Everything works fine for iPad landscape, but when I rotate simulator or run in different device then iPad in landscape camera is not centred. Why?
This is for landscape with camera on center:
After rotation camera is not centred:
Similar issue is for e.g. for landscape iPhone5s:
Why is camera shifted with scene setting .AspectFit with other device then iPad in landscape?
You can try out or experiment with this project on bitbucket I made.
EDIT: When I don't use camera, everything is on its place.

Set the scene anchor point to 0.5, 0.5 to center your camera onto the scene , there is an issue with the view to scene conversion, and will draw in the top left corner instead of the center. (Also, you will notice your hello world is off, this is because it is not accounting for the anchor change)
Perhaps the lack of a camera will make the scene translate where it draws to inside of the black bars, I have no idea.

Related

Scale sceneView to fit screen

I am developing a sample game using SceneKit and Swift in Xcode, I added a ship node (default) and add some animations. The problem is that the sceneView does not fit the screen because the aspect ratio does not seems to bee 16:9 as the screen of an average iPhone screen size. How can I scale the sceneView to fit the screen?
I found out that the best way of solving this issue was to set the Launch Screen File = Main

Why doesn't SKCameraNode center if aspect mismatch? Bug?

Is there a bug in SKCameraNode when used with .AspectFill on devices where the aspect ratio of the SKScene does not match that of the devices view?
I have a minimal demo of the issue I see: an SKScene created in an SKS file, to be 768w x 1024h, filled with an image (also 768w x 1024h). It's loaded with .AspectFill. An SKLabel is positioned in the middle of the scene programmatically. The demo is simply the out-of-the-box iOS template for a SpriteKit game, with a background image added.
An iPad in Portrait (so 768w x 1024h) displays this fine. An iPhone 6+ in Portrait (414w x 736h) displays fine. An iPhone 5S (320w x 568h) displays fine.
If I add a camera to the scene, position it in the middle by setting its coordinates to (384, 512) in the SKS file and set the scene to use it, the iPad is fine but now the iPhones (and any other device with a aspect ratio other than 3:4) does NOT work. It displays the right-hand side of the scene. It is not centered. Screen shot from the iPhone below.
The camera being in the middle of the scene, should ALWAYS work.
I am currently using a work-around. When you use .AspectFill the sides of the scene are cropped by an amount - let's call it cropAmount - to fit on the narrower screen. The work-around is to move the camera left, so it is off-center by cropAmount, then the scene displays correctly.
The background image here is an #3x of a 768w x 1024h background for my game. I've put in green the cropAmount corresponding to the SKView for 9:16, and in red the scene bounds. Given the camera is set in the middle of the scene, same as the label and the pink dot in the middle of the image, why is the center of the view not also there?
If this is a bug, and I leave in my "fix" where I offset the camera by cropAmount, later updates could break production code running on devices.
Also I am not using .ResizeFill as it doesn't fix the camera node issue, and would also mean that the assets are incorrectly sized and positioned in the scene for the thousands of lines of code and dozens of SKS files I already have over 6 months of work.
Question has been edited. Originally I had my "fix" added as an extension but this just caused confusion so I have removed it.

Flash CameraUI orientation is wrong

We're developing an AIR app for android and iOS. An important part of the app is taking photos. Using flash.media.CameraUI works perfectly on android, but we experience problems on iOS.
In the iOS camera application, when we rotate the iPad, the orientation is wrong: If we rotate the pad clockwise, the image is rotated anticlockwise. The UI buttons have the correct orientation though, and when the photo is taken, the resulting bitmap has the right orentation based on the orientation of the camera, not the actual view on the screen.
Looking at different camera apps, I notice that when the pad is rotated so the orientation changes clockwise, the camera does three things: First, the displayed image immediately becomes rotated 90 degrees anti-clockwise (so it looks wrong). Then, the image slowly rotates 90 degrees clockwise, to restore the correct orientation. In addition, the UI buttons change orientation so the text is displayed correctly.
It seems as in our app, it only rotates the image slowly without doing the first immediate rotation. Thus, the end result is wrong.
Anyone know how to fix this?
After some more research, I found that the issue isn't just restricted to AIR.
UIImagePickerController camera view rotating strangely on iOS 8 (pictures)

iAd banner deform my scene

I just add an iAd banner to my sprite kit game but it deform the scene because there are balloons in my scene and with iAd banner the balloons are not rounded anymore.
So what I did is to change the property from
SKSceneScaleMode.AspectFill
to
SKSceneScaleMode.AspectFit
So the balloons look rounded again but I have vertical black strips at the left and the right of my scene.
Any solution to remove the black strips ? or to keep rounded balloons with aspectFill ?
Thank you ! SDK iOS 8, Xcode 6.4
You added the iAd banner. It has fixed height. To still keep all of your scene visible iOS has to scale the size of your scene. AspectFill will just make the Scene fit the view, and resizes it also not proportional.
AspectFit uses an proportional scale so there must be space on the left and the right. The only thing you can do to avoid black spaces and keep the scene proportinal.
The only thing you can do is to resize the scene:
[MyScene sceneWithSize:CGSizeMake(skView.bounds.size.width, skView.bounds.size.height - 50)];
(Assuming the iAd banner is 50pt)

IOS Preview in landscape with correct zoom

Who can give me an minimal example in IOS 5 or higher
of an app that captures the video of the backside cam with the following requirements:
The resolution of the image captured by the camera is 1280x720
The preview layer is a AVCaptureVideoPreviewLayer and fills the full screen on both IPhone 5 and 4
The orientation of both video and preview is LandScapeRight
If I want to zoom the preview, I correctly zoom into the center of my landscape image
I got everything working until 4.). But everytime I try to apply the zoom with
viewLayer.affineTransform = CGAffineTransformMakeScale(2, 2);
I observe that in landscape orientation the center of the focused image is left below the center of the unzoomed image. That is the problem I am trying to solve. So if I set the scale to 1, 1.3, 1.6 or 2.0 I want to always see the center of my unzoomed image.

Resources