我对 PlayerIndex 以及如何使用它有疑问。
问题是第二个控制器(controllingPlayer2)有时需要为“null”(例如,对于一个玩家模式),但 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--;
}