在方向改变时暂停游戏,objective-c/精灵套件
我想在设备定向启动时暂停游戏。我的viewcontroller中有此方法,效果很好:在方向改变时暂停游戏,objective-c/精灵套件,objective-c,sprite-kit,Objective C,Sprite Kit,我想在设备定向启动时暂停游戏。我的viewcontroller中有此方法,效果很好: - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { NSLog(@"I am starting to rotate, should pause game.."); } 但是如何从我的场景中听到设备的旋转,在那里实际的
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
NSLog(@"I am starting to rotate, should pause game..");
}
但是如何从我的场景中听到设备的旋转,在那里实际的游戏正在进行。希望我已经讲清楚了。谢谢你的帮助 您可以使用
NSNotification
。按照代码,在ViewController init中添加以下行:
[[NSNotificationCenter defaultCenter]
postNotificationName:@"RotateNotification"
object:self];
然后在SKScene init中添加以下行:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(receiveNotification:)
name:@"RotateNotification"
object:nil];
还要将调用的方法添加到场景:
-(void) receiveNotification:(NSNotification *)notification
{
NSLog (@"Received notification");
// do what you have to do here...
}
你试过在场景中使用相同的代码吗?是的,willRotate。。。不会因为方向改变而被解雇。。