Game Development Reference
In-Depth Information
}
[self enumerateChildNodesWithName:backgroundName
usingBlock:^(SKNode *node, BOOL *stop) {
node.position = CGPointMake(node.position.x -
backgroundMoveSpeed * timeSinceLast, node.position.y);
if (node.position.x < - (node.frame.size.width + 100)) {
// if the node went completely off screen (with some extra
pixels)
// remove it
[node removeFromParent];
}}];
if (self.currentBackground.position.x < -500) {
// we create new background node and set it as current node
ERGBackground *temp = [ERGBackground generateNewBackground];
temp.position = CGPointMake(self.currentBackground.position.x
+ self.currentBackground.frame.size.width, 0);
[self addChild:temp];
self.currentBackground = temp;
}
}
You can adjust the speed in Common.h to check if the scrolling is really infinite.
You can do this by modifying backgroundMoveSpeed . There are some optimizations
that can be done about this. Instead of creating new nodes each time, we could just
keep two backgrounds in memory at all times and just reposition them every time
one went off the screen. But this way, you are limited to the same background image.
Adding a score label
The next thing we need to have in our game is a label that shows how far we have
gone. First, add two new properties to ERGMyScene.h :
@property (strong, nonatomic) SKLabelNode *scoreLabel;
@property (assign) double score;
After this, add a new label and actions for it in the scene initWithSize: method:
self.score = 0;
self.scoreLabel = [[SKLabelNode alloc] initWithFontNamed:@"Ch
alkduster"];
self.scoreLabel.fontSize = 15;
self.scoreLabel.color = [UIColor whiteColor];
self.scoreLabel.position = CGPointMake(20, 300);
 
Search WWH ::




Custom Search