Game Development Reference
In-Depth Information
How to do it...
As we did in the starter kit, follow the same steps to create a SKScene and add a SKS-
priteNode method to it:
1. Create the SpriteKit Game Template from Xcode.
2. A default ViewController and scene will be created for you.
3. Typecast the ViewController view to SKView by enabling the showsFPS and
showsNodeCount properties to YES .
// Configure the view.
SKView * skView = (SKView *)self.view;
skView.showsFPS = YES;
skView.showsNodeCount = YES;
4. Create a scene using a class method of SKScene specifying the size of the scene
also, and then present that scene on the SKView typecasted before.
// Create and configure the scene.
SKScene * scene = [SKScene
sceneWithSize:skView.bounds.size];
scene.scaleMode = SKSceneScaleModeAspectFill;
// Present the scene.
[skView presentScene:scene];
All this should be done in the - (void)viewWillLayoutSubviews meth-
od.
5. Now we have to add some sprite to the scene we created earlier. Create an object
of SKSpriteNode by calling a class method and specifying an image of the sprite.
Now assign the location where it has to be placed and lastly add it to the scene.
SKSpriteNode * spriteNode = [SKSpriteNode
spriteNodeWithImageNamed:@"Spaceship.png"];
spriteNode.position = CGPointMake(100,100);
[self addChild:spriteNode];
Search WWH ::




Custom Search