簡體   English   中英

從 SKScene 獲取命令鍵

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM