Game Development Reference
In-Depth Information
How to do it...
Now our project template is ready to hold together some advanced physics behaviors. To
accommodate these behaviors, we also need to tweak some code in the project. Perform the
following steps to update the project as per our requirements:
1. Open the GameScene.m file available with the code bundle of this chapter; this
class creates a scene that will be plugged into the game. Remove all the code from
this class and just add the following function:
-(id)initWithSize:(CGSize)size {
if (self = [super initWithSize:size]) {
self.backgroundColor = [SKColor
colorWithRed:0.15 green:0.15 blue:0.3 alpha:1.0];
}
return self;
}
This initWithSize method creates an empty scene with specified size. The
code written inside the init function changes the background color of the scene.
We can tweak the rgb to get the desired background color.
2. Now open GameViewController.m . Remove all the code from this file and
add the following function:
-(void)viewWillLayoutSubviews {
[super viewWillLayoutSubviews];
// Configure the view.
SKView * skView = (SKView *)self.view;
if (!skView.scene) {
skView.showsFPS = YES;
skView.showsNodeCount = YES;
// Create and configure the scene.
GameScene * scene = [GameScene
sceneWithSize:skView.bounds.size];
scene.scaleMode = SKSceneScaleModeAspectFill;
// Present the scene.
Search WWH ::




Custom Search