Game Development Reference
In-Depth Information
Add this code right after it:
myLabel.name = @"theLabel";
Find the update: method; it looks like this:
- (void)update:(CFTimeInterval)currentTime
Insert the following code into it:
[self enumerateChildNodesWithName:@"theLabel" usingBlock:^(SKNode
*node, BOOL *stop) {
node.position = CGPointMake(node.position.x - 2, node.
position.y);
if (node.position.x < - node.frame.size.width) {
node.position = CGPointMake(self.frame.size.width, node.
position.y);
}
}];
This method first finds the child node with the name "theLabel" , and as we named
our label the same, it finds it and gives control to the block inside. The child that it
found is a node. If it finds other nodes with the name " theLabel" , it will call the
same block on all of them in the order they were found. Inside the block, we change
the label position by 2 pixels to the left, keeping the vertical position the same.
Then, we do a check, if the position of the label from the left border of the screen is
further than the length of the label, we move the label to the right-hand side of the
screen. This way, we create a seamless movement that should appear to be coming
out of the right-hand side as soon as the label moves off screen.
But if you run the project again, you will notice that the label does not
disappear. The label takes a bit longer to disappear and blinks on screen
instead of moving gracefully.
 
Search WWH ::




Custom Search