2012-07-08 133 views
0

我正在創建一個程序,您在其中執行rep伸展操作,因此它會向代表的數量添加一個。我想每個代表之間有一個時間間隔(不是當前問題)。我有這個嵌套在AllFramesReadyEventArgs內。問題是,由於SDK在整個程序中使用了AllFramesReadyEvent,所以它是一個無限循環。當我不想要它時,我如何在不重複的情況下做每個代表?提前致謝。AllFramesReady重複循環

if (skeleton.TrackingState == SkeletonTrackingState.Tracked) 
{ 
    int whereIsX = (int)Canvas.GetLeft(ellipse1); 
    int whereToX = (int)Canvas.GetLeft(pspine); 
    whatToMultiplyX = whereToX/whereIsX; 

    int whereIsY = (int)Canvas.GetTop(ellipse1); 
    int whereToY = (int)Canvas.GetTop(pspine); 
    whatToMultiplyY = whereToY/whereIsY; 

    Canvas.SetTop(ellipse1, Canvas.GetTop(ellipse1) * whatToMultiplyY); 
    Canvas.SetLeft(ellipse1, Canvas.GetLeft(ellipse1) * whatToMultiplyX); 

    for (int i = 0; i < Doctor_ShoulderX.Count; i++) 
    { 
     Canvas.SetTop(doctorHand, Doctor_HandY[i] * whatToMultiplyY); 
     Canvas.SetTop(doctorElbow, Doctor_ElbowY[i] * whatToMultiplyY); 
     Canvas.SetTop(doctor_Shoulder, Doctor_ShoulderY[i] * whatToMultiplyY); 

     Canvas.SetLeft(doctorHand, Doctor_HandX[i] * whatToMultiplyX); 
     Canvas.SetLeft(doctorElbow, Doctor_ElbowX[i] * whatToMultiplyX); 
     Canvas.SetLeft(doctor_Shoulder, Doctor_ShoulderX[i] * whatToMultiplyX);       

     handX = Canvas.GetLeft(handright); 
     handY = Canvas.GetTop(handright); 

     elbowX = Canvas.GetLeft(elbowright); 
     elbowY = Canvas.GetTop(elbowright); 

     shoulderX = Canvas.GetLeft(shoulderright); 
     shoulderY = Canvas.GetTop(shoulderright); 

     shoulder_x.Text = "Shoulder X: " + shoulderX.ToString(); 
     shoulder_y.Text = "Shoulder Y: " + shoulderY.ToString(); 

     elbow_x.Text = "Elbow X: " + elbowX.ToString(); 
     elbow_y.Text = "Elbow Y: " + elbowY.ToString(); 

     hand_x.Text = "Hand X: " + handX.ToString(); 
     hand_y.Text = "Hand Y: " + handY.ToString(); 

     Patient_HandX.Add(handX); 
     Patient_HandY.Add(handY); 

     Patient_ElbowX.Add(elbowX); 
     Patient_ElbowY.Add(elbowY); 

     Patient_ShoulderX.Add(shoulderX); 
     Patient_ShoulderY.Add(shoulderY); 
    } 
} 
+1

你可以寫更多關於什麼是重複?我在這裏看到循環與開始和結束。問題出在循環或循環本身? – Fixus 2012-07-08 17:19:09

+0

@Fixus問題是,allframesready重複我想要的循環 – 2012-07-08 21:05:00

+0

@Fixus檢查編輯 – 2012-07-09 00:47:19

回答

1

我將使用的答案比事業更評論寫作可以處理:)

aleframesready動作在每一幀調用。所以如果你在這裏有限制20循環

for (int i = 0; i < Doctor_ShoulderX.Count; i++) 

它將被調用從0到20每次。你應該在類中創建一個靜態布爾變量。代碼從循環中移出後,將其設置爲false(如果開始時爲真)。在調用循環之前,檢查變量是否設置爲true。如果是,調用循環,如果沒有,只是繼續

+0

不錯的一個Fixus! – 2012-07-09 17:36:57