2 sprites using each a different controller

I have 2 sprites which have to be controlled each from a different player using a different game pad.

I created a class and put a property Vector2 direction. Inside that property I wrote the following.

GamePadState gamepadState1 = GamePad.GetState(PlayerIndex.One);
if (gamepadState1.ThumbSticks.Left.X != 0)
inputDirection.X += gamepadState1.ThumbSticks.Left.X;
and similar for Y

Now inside the Game1.cs I create 2 objects and I only need to write inside Update
player1.Update(gameTime, Game.Window.ClientBounds);
player2.Update(gameTime, Game.Window.ClientBounds);

In order to distinguish the one object from the other, I changed the sprite constructor and added a string. At the object creation the first has this named “left” and the second “right”

Moreover I changed the property direction inside the sprite class into the following:

GamePadState gamepadState1 = GamePad.GetState(PlayerIndex.One);
if (side == “left”)
{
if (gamepadState1.ThumbSticks.Left.X != 0)
inputDirection.X += gamepadState1.ThumbSticks.Left.X;
}

GamePadState gamepadState2 = GamePad.GetState(PlayerIndex.Two);
if (this.side == “right”)
{
if (gamepadState2.ThumbSticks.Left.X != 0)
inputDirection.X += gamepadState2.ThumbSticks.Left.X;
}

The problem is that left works fine with game pad One, but game pad Two does not bring any result to the game. Why?

left and right are correctly added to both objects, I check it with the debugger. And moving the second pad jumps correctly into the condition. For some reason the second object doesn’t realize that it should obey to the second game pad.

Any ideas?

Thanks

Try playerindexes 3 or 4? Maybe the 2nd gamepad isn’t being picked up as player 2.

If it is 2 and is getting a true condition, then the code is messed up elsewhere.

So many questions for this one…

DX or OGL?

XBOX ONE Pad or third party?

3.7 or 3.8?

Windows, Linux, or another creature, Mac?

It didn’t work either. I think it has to do with the architecture, but I do not know why exactly. I’m pretty sure that if I make another similar class it will work, but this would be nonsense programmatically.

Windows shared project (OpenGL) v3.8

Figured, if you search the forum, you will find the solution, good luck.