Reputation: 524
I know there is an issue where if you plan to make a spritekit game in landscape mode then you need to set up your coordinate system in the view controller's viewWillLayoutSubviews method instead of viewDidLoad in order to properlly set up the coordinate system.
I've done this and in XCode 5 it displayed properly in both the simulator and the device. But when I upgraded to 6, it displays my height and widths reversed on the simulator, but still correctly on the device.
This is my code in viewWillLayoutSubviews:
- (void) viewWillLayoutSubviews
{
[super viewWillLayoutSubviews];
SKView * skView = (SKView *)self.view;
if (!skView.scene)
{
//screenHeight and Width still have to be reversed to work on actual device. On simulator however they must not be reversed.
//screenWidth = (int)((CGRect)[[UIScreen mainScreen] bounds]).size.width;
//screenHeight = (int)((CGRect)[[UIScreen mainScreen] bounds]).size.height;
screenHeight = (int)((CGRect)[[UIScreen mainScreen] bounds]).size.width;
screenWidth = (int)((CGRect)[[UIScreen mainScreen] bounds]).size.height;
[self presentNewScene:startScene];
}
}
screenHeight and screenWidth are the two core variables I use to base all other coordinates in my game off of. The commented section would display correctly in landscape mode on the simulator, but reversed on device. The uncommented section displays reversed on the simulator but correctly on the device.
I'm assuming that the actual device's display is the one that matters. But it bothers me that I can't test on the simulator unless I switch out the uncommented parts for the commented. Is anyone else experiencing this? Is what I'm doing the proper way to go about this or is there a different way I should be handling this now that it's XCode 6?
Upvotes: 0
Views: 300
Reputation: 11
I think it's an iOS problem , cause : i use a simulator and an iPad with iOS 8.+ and, with "width == width and height == height" , they show the exact thing (images perfectly centered).
But if i use an iPhone with iOS 7 it shows the wrong position.
If I revert the sizes i get reversed results.
So for iOS 8.+ "width == width", for iOS 7.0 (not tested on 7.1) "width == height"
Upvotes: 1