2012-05-14 10 views
0

XNAのGSMキットの入力の一部を見てみると、 の一部には2つのパラメータがあり、その他のパラメータは1つしかないことに気付きました。どうして?両者に違いはありますか?InputeStateメソッドのパラメータ

ここに2つの例があり、その後にコード全体へのリンクがあります。あなたが入力を探すために、特定の人物を指定したい場合は

 /// <summary> 
    /// Checks for a "pause the game" input action. 
    /// The controllingPlayer parameter specifies which player to read 
    /// input for. If this is null, it will accept input from any player. 
    /// </summary> 
    public bool IsPauseGame(PlayerIndex? controllingPlayer) 
    { 
     PlayerIndex playerIndex; 

     return IsNewKeyPress(Keys.Escape, controllingPlayer, out playerIndex) || 
       IsNewButtonPress(Buttons.Back, controllingPlayer, out playerIndex) || 
       IsNewButtonPress(Buttons.Start, controllingPlayer, out playerIndex); 
    } 


    /// <summary> 
    /// Checks for a "menu cancel" input action. 
    /// The controllingPlayer parameter specifies which player to read input for. 
    /// If this is null, it will accept input from any player. When the action 
    /// is detected, the output playerIndex reports which player pressed it. 
    /// </summary> 
    public bool IsMenuCancel(PlayerIndex? controllingPlayer, 
          out PlayerIndex playerIndex) 
    { 
     return IsNewKeyPress(Keys.Escape, controllingPlayer, out playerIndex) || 
       IsNewButtonPress(Buttons.B, controllingPlayer, out playerIndex) || 
       IsNewButtonPress(Buttons.Back, controllingPlayer, out playerIndex); 
    } 

Full InputState Code

答えて

2

最初の機能は、プレイヤーが一時停止ボタンを押したが、どのボタンを押したかを教えてくれないことを示しています。 2番目の機能は、プレイヤーがメニューをキャンセルしたことを伝えます。 これはこの関数のout PlayerIndex playerIndexパラメータです。

基本的に、開発者は入力検出機能から受け取った情報を渡すかどうかを選択しました。

なぜ、どのプレイヤーがメニューを閉じるのが重要かと思います。たとえばPESでは、すべてのプレイヤーが設定を行い、キャンセルメニューボタンを押します。両方のプレイヤーがキャンセルボタンを押したときにのみ、メニューは実際に閉じます。

推測すると、誰が一時停止を要求したかについての情報は関係がないため、推測されません。

+0

@hexxagonalああ、両方に感謝します。 私の次の質問につながります。なぜ、いくつかのメソッドには1つのパラメータしかなく、他のメソッドには2しかないのですか?たとえば、IsMenuCancelはplayerIndexを出力しますが、isMenuUpは出力しません。 –

+0

気にしないで、今あなたの完全な反応を見ます。以前は、あなたが書いた最初の2つの段落しか表示されませんでした。 –

+1

私が編集した後、私は、開発者が情報以外のものを渡すことが適切であると思うケースがあると思います。 –

1

の制御プレーヤーが使用されています。指定されていなければ、すべてのコントローラーを調べます。 Player Indexは、提供された入力を誰が押したかを指定します。これがoutパラメータである理由です。

関連する問題