Game Development Reference
In-Depth Information
Scenes
An object where you place all of your other objects is the SKScene object. It represents
a single collection of objects such as a level in your game. It is like a canvas where
you position your Sprite Kit elements. Only one scene at a time is present on SKView .
A view knows how to transition between scenes and you can have nice animated
transitions. You may have one scene for menus, one for the gameplay scene,
and another for the scene that features after the game ends.
If you open your ViewController.m file, you will see how the SKScene object is
created in the viewDidLoad method.
Each SKView should have a scene, as all other objects are added to it. The scene and
its object form the node tree, which is a hierarchy of all nodes present in the scene.
Open the ERGMyScene.m file. Here, you can find the method where scene
initialization and setup take place:
- (id)initWithSize:(CGSize)size
The scene holds the view hierarchy of its nodes and draws all of them. Nodes are
very much like UIViews; you can add nodes as children to other nodes, and the
parent node will apply its effects to all of its children, effects such as rotation or
scaling, which makes working with complex nodes so much easier.
Each node has a position property that is represented by CGPoint in scene
coordinates, which is used to set coordinates of the node. Changing this position
property also changes the node's position on the screen.
After you have created a node and set its position, you need to add it to your scene
node hierarchy. You can add it either to the scene or to any existing node by calling
the addChild: method. You can see this in your test project with the following line:
[self addChild:myLabel];
After the node has been added to a visible node or scene, it will be drawn by the
scene in the next iteration of the run loop.
Nodes
The methods that create SKLabelNode are self-explanatory and it is used to represent
text in a scene.
The main building block of every scene is SKNode . Most things you can see on the
screen of any given Sprite Kit game is probably a result of SKNode .
 
Search WWH ::




Custom Search