Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
544 views
in Technique[技术] by (71.8m points)

ios7 - Pausing a sprite kit scene

@property (SK_NONATOMIC_IOSONLY, getter = isPaused) BOOL paused;

I found this line of code that I could add into my project, how would I pause my whole game?

For example:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
for (UITouch *touch in touches)
{
    SKSpriteNode *pause = (SKSpriteNode*)[self childNodeWithName:@"pause"];
    CGPoint location = [touch locationInNode:self];
    // NSLog(@"** TOUCH LOCATION ** 
x: %f / y: %f", location.x, location.y);

    if([pause containsPoint:location])
    {
        NSLog(@"PAUSE GAME HERE SOMEHOW");
    }
}

}

As you can see, I have the button set up. When i select it, how would I pause the whole scene? And then resume it when someone hits a resume button.

OK SO I got some advice to call

  self.scene.view.paused = YES;

except here is the problem, in my app delegate

- (void)applicationWillResignActive:(UIApplication *)application{


SKView *view = (SKView *)self.window.rootViewController.view;
view.paused = YES;}

and

- (void)applicationDidBecomeActive:(UIApplication *)application{

    SKView *view = (SKView *)self.window.rootViewController.view;
    view.paused = NO;

I make it a type SKView, when it is actually an SKScene. Anyway to fix this? Do you suggest that I make all my scenes into views by retyping all the code?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Use SKView's isPaused property:

Swift:

scene.view?.isPaused = true

Objective C:

self.scene.view.isPaused = YES;

This will stop all actions and physics simulation.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...