Game Development Reference
In-Depth Information
How to do it...
Internally, the life cycle is executed as per the scenes—nodes are added and actions applied
on these nodes. It also includes attaching some physics bodies to the nodes, support for
cropping, applying animation and effects to all or a part of the content, detecting forces and
collision, drawing in OpenGL, and many more things.
Apart from all this, there is an overridden update method in SKScene , which is called for
each frame of the game with the current time interval as a parameter. There you can add
your actual game logic specifying what to do at what time and many more things as it is
called by every frame that is rendered.
For an example, we can track the difference in time between the current time and the last
updated time.
1. As the current time interval is received in the update method, define the properties
for difference in time and last updated time.
@property (nonatomic, assign) NSTimeInterval
lastUpdatedTime;
@property (nonatomic, assign) NSTimeInterval
diffTime;
2. Now calculate difference in time by subtracting the last updated time from the cur-
rent time and updating the lastUpdatedTime to the current time.
self.diffTime = currentTime - self.lastUpdatedTime;
self.lastUpdatedTime = currentTime;
3. At last the update method looks like this:
- (void)update:(CFTimeInterval)currentTime
{
/* Called before each frame is rendered */
self.diffTime = currentTime -
self.lastUpdatedTime;
self.lastUpdatedTime = currentTime;
}
Search WWH ::




Custom Search