暂停精灵套件场景 [英] 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?
例如:
-(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 ** \nx: %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;
除了这是问题,在我的app委托中
except here is the problem, in my app delegate
- (void)applicationWillResignActive:(UIApplication *)application{
SKView *view = (SKView *)self.window.rootViewController.view;
view.paused = YES;}
和
- (void)applicationDidBecomeActive:(UIApplication *)application{
SKView *view = (SKView *)self.window.rootViewController.view;
view.paused = NO;
我把它变成SKView类型,当它实际上是SKScene时。有任何解决这个问题的方法吗?您是否建议我通过重新输入所有代码将所有场景变为视图?
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?
推荐答案
使用 SKView
的 已暂停
属性:
Use SKView
's paused
property:
Swift :
scene.view?.paused = true
目标C :
self.scene.view.paused = YES;
这将停止所有动作和物理模拟。
This will stop all actions and physics simulation.
这篇关于暂停精灵套件场景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!