I recently started developing my first iPhone app, and it will be a 2D game. Everything is going well so far, and the project already includes more than a thousand lines of code.
However, I just entered into a small problem. As with many games, you need to pause it. My first attempt was to simply use this in code where a pause should occur.
self.view.paused = true;
It worked fine until I needed animations so that after someone pressed the pause button. Imagine a new node sprite shifted from the bottom of the screen, which includes some details about the current account and so on. Using the code above, of course, all animations will be stopped.
My new idea was to simply stop all nodes that needed to be stopped separately. I got this working using this piece of code.
[self enumerateChildNodesWithName:@"name" usingBlock:^(SKNode* node, BOOL* stop) { node.paused = true; node.speed = 0.0; }];
I tried a couple of runs and thought that I finally found a solution when I entered into another problem. Some of the nodes of the sprite games that need to be stopped are created periodically after a certain time. The following code is responsible for this behavior.
SKAction* createPeriodically = [SKAction repeatActionForever:[SKAction sequence:@[[SKAction performSelector:@selector(create) onTarget:self],[SKAction waitForDuration:15.0]]]]; [self runAction:createPeriodically];
As you can see, I use waitForDuration to delay the creation of sprite nodes. Now, when I pause all the nodes, the time still continues, and thus waitForDuration ends after the set time and a node sprite is created, although all the others are paused and not moved.
Hope you guys were able to understand my problem. I am looking for a way to temporarily suspend the mechanism for creating sprite nodes, while still having the ability to create a new sprite node and perform actions for the new one. Any help is appreciated. Thanks.