问题描述
我刚刚创建了一个2人游戏(如ShapeGame)的但问题是,当一个玩家从游戏场景左派,我无法检测哪一个(哪个球员)从比赛还剩的
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.
认为,有2辆在游戏中。首先检测播放器(称之为PLAYER1)使用左边和player2使用正确的。当PLAYER1离开现场,突然player2需要离开汽车的控制,如果PLAYER1重新加入比赛,再次PLAYER1收回左车的控制和player2采取正确的汽车的控制权。
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++;
}
}
问题是计划让 ID = 0
对于首次检测播放器(称之为PLAYER1)为1秒检测播放器(称之为player2)。当player2从游戏和重新加入左派,是没有问题的。它再次发生 ID = 1
。但是当PLAYER1从游戏左派,player2取 ID = 0
因为它是在这一点上检测到的第一玩家
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.
任何解决方案?
推荐答案
每个球员都有骨骼数组索引:
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];
您可以使用该索引来识别你的球员如果离开和回来。结果
但是,如果两个玩家离开视线的Kinect的它不批玩家指数是正确的,当他们再次进入Kinect的知名度。
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.
这篇关于Kinect的SDK播放器检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!