So i'm creating a game using the Beta2 SDK for Kinect. The issue i am having is that in the middle of gameplay if another person enters the Kinects FOV it stops tracking the player and will not track anyone else for several minutes. Same deal if the player leaves the FOV and reenters it.
Here is what im using to detect players.
void nui_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
{
int playersAlive = 0;
// reset lists
skeletons = new Dictionary<int, SkeletonData>(); //create a new list for skeletons
menuSkeleton = new List<SkeletonData>();
initialPlayers = new Dictionary<float, SkeletonData>(); //create a new list for initialPlayers
foreach (SkeletonData s in e.SkeletonFrame.Skeletons) //for each skeleton the kinect has detected
{
if (s.TrackingState == SkeletonTrackingState.Tracked) // players found
{
menuSkeleton.Add(s);
if (initialized) // after initialization
{
skeletons.Add(s.TrackingID, s);
}
else // before initialization
initialPlayers.Add(s.Joints[JointID.ShoulderCenter].Position.X, s); //if we are not initialized then add this player to the inital player list.
playersAlive++;
}
}
if (playersAlive == TOTAL_PLAYERS_ALLOWED) // If there is one player
{
if (!inMiniGame) // Before the game starts
gameStart = DateTime.Now; // Reset initialization timer
if (!initialized) // Before initialization // NOTE TO SELF I TOOK OUT && inMenu
{
InitializePlayers();
if (DateTime.Now.Subtract(gameStart).TotalMilliseconds > INITIALIZATION_WAIT_TIME)
{
initialized = true;
// initialize timers from fixed starting time
if (inMiniGame) //if the game has started
{
gamePause = gameStart;
//TODO ERIC: Initialize any Timers Here
}
}
}
}
}
/// <summary>
/// this function initializes the players adding them to a list
/// and making one of the players the menu controller, for LIM we will need to change the code so that the
/// game only recognizes and supports one player at a time
/// variable names will need to be change as well.
/// </summary>
private void InitializePlayers()
{
List<float> initialPos = new List<float>(); // used to track starting positions
players = new Dictionary<int, Player>();
foreach (float pos in initialPlayers.Keys)
{
initialPos.Add(pos); //add position of each inital player to list
}
float first = initialPos[0]; // left player first, right second
Player player = new Player(initialPlayers[first].TrackingID, true);
player.PlayerNumber = PLAYER_ONE;
player.Skeleton = initialPlayers[first];
player.Specifics = new PlayerSpecifics(player.PlayerNumber);
player.Specifics.PauseTimer = gameStart;
players.Add(initialPlayers[first].TrackingID, player);
menuController = initialPlayers[first].TrackingID; //menu controller is player 1
}
This is a one player game. Also when the game starts Initialize is set to false, and gets set to true when i go from the games menu into the gameplay.
So can anyone see any issues with this code block that would cause the kinect to lose players as they enter/exit the FOV? and not re-track them?
Thank you for any help.