To continuously populate the screen with bubbles you can use the update:
method of your SKScene
. Here is how to do it.
First, add a property that will store a date when you last added a bubble.
@property(nonatomic, strong) NSDate *lastBubbleCreationDate;
Then, change your update:
method to:
-(void)update:(CFTimeInterval)currentTime
{
// Create new bubble every 5s.
if (ABS([_lastBubbleCreationDate timeIntervalSinceNow]) > 5)
{
[self createBubbleNode];
}
}
Finally, in your createBubbleNode
method you have to store the time when you created last bubble:
-(void)createBubbleNode
{
// Your code here
// Set the date to now.
_lastBubbleCreationDate = [NSDate date];
}
You also need to call createBubbleNode
to set the initial value of the _lastBubbleCreationDate
. You can do this in didMoveToView:
method. Just add this method to your scene implementation:
- (void)didMoveToView:(SKView *)view
{
// Creates first bubble and sets the initial value of the _lastBubbleCreationDate
[self createBubbleNode];
}
In next levels you can just change the 5s
value to create bubbles more often which will make the game more difficult.