Kinect SDK player detection
Asked Answered
L

1

8

I just created a 2 player game (like ShapeGame) but the problem is when one of the players lefts from the game scene, I can't detect which one (which player) left from the game.

Think that there are 2 cars in the game. First detected player (call it player1) uses left one and player2 uses right one. When player1 left the scene, suddenly player2 takes the control of left car, and if player1 rejoins the game, player1 takes back control of the left car again and player2 takes control of the right car.

int id = 0;  
foreach (SkeletonData data in skeletonFrame.Skeletons)
{
    if (SkeletonTrackingState.Tracked == data.TrackingState)
    {
        // do some work

        id++;
    }
}

The thing is program gives id = 0 for first detected player (call it player1) and 1 for second detected player (call it player2). When player2 lefts from the game and rejoins, there is no problem. It again takes id = 1. but when player1 lefts from the game, player2 takes id = 0 because of it is the first detected player at this point.

Any solutions?

Licensee answered 12/5, 2012 at 9:33 Comment(0)
G
3

Every player has an index in the Skeleton array:

void nui_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e) {
    SkeletonFrame sf = e.SkeletonFrame;
    //check which skeletons in array are active and use that array indexes for player index
    SkeletonData player1 = sf.Skeletons[playerIndex1];
    SkeletonData player2 = sf.Skeletons[playerIndex2];

You can use that index to identify your players if one leave and comes back.
But if both players leave the sight of the Kinect it is not granted that the player index is correct when they enter the Kinect visibility again.

Grosz answered 12/5, 2012 at 9:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.