Game Development Reference
In-Depth Information
How it works...
As explained in the structural block diagram of the How it works... section of the Learning
the basics of SpriteKit - The FlyingSpaceship tutorial recipe, it's deeply linked with the
UIKit framework. For building a game, we should have an environment, which is our
scene, and some entities visible over the environment, which are the sprites. So to make it
work, or should I say to make something visible on the screen, an environment (that is,
scene) is created and on it entities (that is, sprites) are added, as follows:
• When we typecast UIView in to SKView , we enter the arena of SpriteKit:
SKView * skView = (SKView *)self.view;
• For debugging purposes, we enable two Boolean parameters to show FPS (Frames
per second) and NodesCount (the number of nodes added to the scene):
skView.showsFPS = YES;
skView.showsNodeCount = YES;
• When creating a scene, we need to specify the size of the scene that is exactly the
content size and the scale mode so that the scene fits in SKView (that is, scale per-
spective), here the SKSceneScaleModeAspectFill mode is used so that it
fits as per the aspect ratio of the SKView :
SKScene * scene = [SKScene
sceneWithSize:skView.bounds.size];
scene.scaleMode = SKSceneScaleModeAspectFill;
• To make the scene content visible on the view, we present the scene on SKView :
// Present the scene.
[skView presentScene:scene];
• Now about how the sprites work. A sprite object is created by a class method that
instantiates a node having an image as its content:
SKSpriteNode * spriteNode = [SKSpriteNode
spriteNodeWithImageNamed:@"Spaceship.png"];
• The following line of code specifies the position where exactly the sprite needs to
be placed:
Search WWH ::




Custom Search