I have a question about PlayerIndex and how to use it.
The problem is the second controller (controllingPlayer2) need to be “null” sometimes (for one player Mode, for example) but the GetState cannot accept a null variable.
I have a class (for my gamescreen) like this:
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--;
}
This should do the trick, you can look up how Nullable works here.