[英]Get command key from SKScene
我想為我的 SpriteKit 游戲支持鍵盤,但問題是:
我們從 ViewController 獲取命令鍵:
- (NSArray *)keyCommands {
return @[[UIKeyCommand keyCommandWithInput:@" " modifierFlags:0 action:@selector(fire)]];
}
但是游戲邏輯都是在SKScene中,從ViewController呈現出來的……而且還有多個SKScene……場景是怎么從ViewController得到命令的呢? 或者我們需要進行鍵盤輪詢?
您可以通過NSNotification
發送消息
在SKScene
中添加觀察者,
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(selectorMethod:)
name: @"NOTIFICATION_NAME"
object:nil];
發布通知表格UIViewController
,
NSDictionary *userInfo = @{ @"Key": @"Value" };
[[NSNotificationCenter defaultCenter] postNotificationName: @"NOTIFICATION_NAME" object:nil userInfo:userInfo];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.