Game Development Reference
In-Depth Information
There are two problems with our code. The first issue is that the frame is not
changing when you rotate the screen, it stays the same even if you rotate the
screen. This happens because the scene size is incorrectly calculated at startup.
But we will fix that using the following steps:
1. Locate the Endless Runner project root label in the left pane with our files.
It says Endless Runner, 2 targets, iOS SDK 7.0 . Select it and select the
General pane on the main screen.
There, find the device orientation and the checkboxes near it.
Remove everything but Landscape Left and Landscape Right .
We will be making our game in landscape and we don't need
the Portrait mode.
2.
Next, locate your ERGViewController.m file. Find the viewDidLoad method.
Copy everything after the [super viewDidLoad] call.
3.
Make a new method and add the following code:
- (void) viewWillLayoutSubviews
{
// Configure the view.
[super viewWillLayoutSubviews];
SKView * skView = (SKView *)self.view;
skView.showsFPS = YES;
skView.showsNodeCount = YES;
// Create and configure the scene.
SKScene * scene = [ERGMyScene sceneWithSize:skView.bounds.
size];
scene.scaleMode = SKSceneScaleModeAspectFill;
// Present the scene.
[skView presentScene:scene];
}
4.
Let's see why calculations of frame size are incorrect by default. When the
view has finished its load, the viewDidLoad method is getting called, but the
view still doesn't have the correct frame. It is only set to the correct dimensions
sometime later and it returns a portrait frame before that time. We fix this
issue by setting up the scene after we get the correct frame.
 
Search WWH ::




Custom Search