2013-03-24 3 views
5

세로로 일련의 직사각형을 스크롤하려고합니다. 각 사각형은 다음 사각형과 일정한 거리를 유지합니다. 첫 번째 사각형은 화면 상단에서 10 픽셀 아래에 있으면 안되며, 마지막 사각형은 텍스트 상자보다 20 픽셀 이상 떨어져서는 안됩니다. 즉, Windows Phone에서 SMS 응용 프로그램을 모방합니다.키네틱 스크롤 목록 X 축에서 <Rectangle>

아래의 방법은 이론적으로 직사각형을 동역학으로 스크롤해야하며 경우에 따라 일부 직사각형이 서로 가깝게되어 (결국 겹치기도합니다). 화면의 제스처가 느릴 때 효과가 확대 된 것처럼 보입니다.

private void Flick() 
{ 
    int toMoveBy = (int)flickDeltaY; 
    //flickDeltaY is assigned in the HandleInput() method as shown below 
    //flickDeltaY = s.Delta.Y * (float)gameTime.ElapsedGameTime.TotalSeconds; 

    for (int i = 0; i < messages.Count; i++) 
    { 
     ChatMessage message = messages[i]; 
     if (i == 0 && flickDeltaY > 0) 
     { 
      if (message.Bounds.Y + flickDeltaY > 10) 
      { 
       toMoveBy = 10 - message.Bounds.Top; 
       break; 
      } 
     } 
     if (i == messages.Count - 1 && flickDeltaY < 0) 
     { 
      if (message.Bounds.Bottom + flickDeltaY < textBox.Top - 20) 
      { 
       toMoveBy = textBox.Top - 20 - message.Bounds.Bottom; 
       break; 
      } 
     } 
    } 
    foreach (ChatMessage cm in messages) 
    { 
     Vector2 target = new Vector2(cm.Bounds.X, cm.Bounds.Y + toMoveBy); 
     Vector2 newPos = Vector2.Lerp(new Vector2(cm.Bounds.X, cm.Bounds.Y), target, 0.5F); 
     float omega = 0.05f; 
     if (Vector2.Distance(newPos, target) < omega) 
     { 
      newPos = target; 
     } 
     cm.Bounds = new Rectangle((int)newPos.X, (int)newPos.Y, cm.Bounds.Width, cm.Bounds.Height); 
    } 
} 

저는 정말 벡터를 이해하지 못합니다. 그래서 바보 같은 질문 인 경우 사과드립니다.

답변

0

나는 당신이 달성하고자하는 것을 정말로 완전히 이해하지 못합니다. 하지만 코드에서 문제가 발견 : 당신의 선형 보간 (Vector2.Lerp) 정말 의미가 있습니다하지 않습니다 (또는 내가 뭔가를 놓친 거지?) :

Vector2 target = new Vector2(cm.Bounds.X, cm.Bounds.Y + toMoveBy); // <-- the target is Y-ToMoveBy different from the actual Y position 
Vector2 newPos = Vector2.Lerp(new Vector2(cm.Bounds.X, cm.Bounds.Y), target, 0.5F); // <-- this line is equivalent to say that newPos will be new Vector2(cm.Bounds.X, cm.Bounds.Y + toMoveBy/2); 
float omega = 0.05f; 
if (Vector2.Distance(newPos, target) < omega) // So the only chance to happen is toMoveBy == 0.10 ??? (because you modify `cm` each time `Flick()` is called ? - see next line) 
{ 
    newPos = target; 
} 
cm.Bounds = new Rectangle((int)newPos.X, (int)newPos.Y, cm.Bounds.Width, cm.Bounds.Height); // <-- Equivalent to new Rectangle((int)cm.Bounds.X, (int)cm.Bounds.Y + toMoveBy/2, ...) 
+0

음은 기본적으로 난 그냥 역학적으로 목록을 스크롤 할 수 있도록하려면 터치 입력에 기반한 직사각형 오브젝트. 이것은 스레드 된 SMS 응용 프로그램과 매우 유사한 인터페이스의 XNA 구현입니다. 또한 저는 당신의 대답을 이해하지 못했습니다. 나는 'Lerp'가 목표물에 도달하지 못하고 그 목표에 도달하지 못하기 때문에 if 조건을 추가 했으므로 임계점 인 'omega'가 있으므로 목표에 충분히 가까워지면 목표가 지정됩니다. 그래도 여전히 잘못된 것일 수 있습니다. –

관련 문제