PlayerIndex とその使用方法について質問があります。
問題は、2 番目のコントローラー (controllingPlayer2) が「null」である必要がある場合があることです (たとえば、1 人のプレイヤー モードの場合) が、GetState は null 変数を受け入れることができません。
次のようなクラス(ゲーム画面用)があります:
public GameScreen(PlayerIndex? controllingPlayer, PlayerIndex? controllingPlayer2)
{
this.ControllingPlayer = controllingPlayer;
this.ControllingPlayer2 = controllingPlayer2;
}
public override void HandleInput()
{
// Move the character UP - Problem appears at the GetState Here wanting a PlayerIndex not a null?
if (GamePad.GetState(ControllingPlayer).IsButtonDown(controls.BUp))
{
P1movementY--;
}
// Move the second character UP - Problem appears at the GetState Here wanting a PlayerIndex not a null?
if (GamePad.GetState(ControllingPlayer).IsButtonDown(controls.BUp))
{
P2movementY--;
}