Scene
public class Scene: Node
A Scene
is a node object that holds everything on screen as the root of the node tree. Anything that needs to be displayed must be added to
either the scene directly or a node that is already part of the scene’s tree.
The scene is also responsible for setting up and maintaining the render loop.
In general, this is where all the stuff should happen. Any game using this engine should subclass this and override the update(_:)
method.
- discussion: Unlike other
Node
types it’s safe to force unwrap theCamera
object on a scene. It will always have a default value and unless no other cameras are created it will be the same camera used for each node added to the scene. Also, it probably makes little sense to add a scene as a child to another scene and may cause problems.
-
Undocumented
Declaration
Swift
public class Scene: Node
-
Create a scene of a given size. This will serve as the root node to which all other nodes should be added to.
Declaration
Swift
public override init(size: CGSize)
Parameters
size
The size to make the scene.
Return Value
A new instance of
Scene
. -
This is more or less the game loop.
Note
Although this loop is actually set up in
GameViewController
that’s only because Metal forced that upon me. I may change this back to a CADisplayLink loop at some point but I believe this is easier for cross platform, ie, OSX, tvOS, etc. So this should be the main loop for any game using this engine.Declaration
Swift
public override func update(delta: CFTimeInterval)
Parameters
timeSinceLastUpdate
The amount of time that’s passed since this method was last called.