2012-08-26 5 views
1

저는 C# 및 wpf를 배우고 있습니다. Visual Studio 2012에서 프로젝트를 실행하고 있습니다. C# 및 WPF를 더 잘 배우려면 Simon Says 게임 일 수있는 연습 응용 프로그램을 만들고 있습니다. 창문이 두 개 있어요. 첫 번째 창이 "PLAY!" 버튼을 누르면 다음 창이 열립니다. 이 창에는 4 개의 버튼이 있습니다. 플레이어가 버튼을 순서대로 눌러야하기 때문에 정수 배열을가집니다. 플레이어에게 순서를 보여주기 위해 배열에 생성 된 순서대로 각 단추를 하나씩 애니메이션으로 처리하려고했습니다.애니메이션을 한 번에 하나씩 실행하십시오.

버튼은 4 가지 색상과 각각의 블렌드 스토리 보드에서 만든 애니메이션입니다. 애니메이션은 버튼을 원래 색상에서 빨간색으로 바꾼 다음 2 초 동안 되돌아갑니다.

그러나 애니메이션은 제대로 작동하지만 모든 버튼이 동시에 움직입니다. 첫 번째 버튼이 움직이기를 원했고, 끝나면 다음 버튼이 생기길 원했습니다. 어떻게하면 C#과 WPF를 사용하면 좋을까요? 도와 주셔서 감사합니다. 필요한 경우 코드를 업로드 할 수 있습니다.

애니메이션

public void startbtn_Click(object sender, RoutedEventArgs e) 
{ 
    // Show the animation sequence for each button 
    // up until the current level. (getCurrentLevel is currently set to 5) 
    for (int i = 0; i <= engine.getCurrentLevel(); i++) 
    { 
     // engine.animate(i) returns the button at sequence i to animate 
     animate(engine.animate(i)); 
    } 
} 

private void animate(int index) 
{ 
    // Storyboard for each button is in the format of ButtonAnimation_INDEX where INDEX is 1, 2, 3 or 4 
    Storyboard btnAnimation = (Storyboard)this.Resources["ButtonAnimation_" + index]; 
    if (btnAnimation != null) 
    { 
     btnAnimation.Begin(); 
    } 
} 
+0

System.Threading.Thread.Sleep (2000); – MrFox

+0

첫 번째 애니메이션이 끝나면 이벤트를 얻는 방법이 wpf에 있다고 생각합니다. 다음 애니메이션을 사용하여 다음 애니메이션을 시작할 수 있습니다. 나는 이것을 나 자신으로하지 않고 있었다. 그래서 나는 단지 여기에서 설명하고있다! – Surfbutler

+1

스토리 보드에서 구독 할 수있는 완료 이벤트가 있습니다. http://msdn.microsoft.com/en-us/library/system.windows.media.animation.timeline.completed.aspx –

답변

0

나는 완료 이벤트를 사용하여 파악을 실행하는 기능. 지금 함수가 현재 시퀀스가 ​​현재 레벨보다 낮은 지 확인합니다. 그것이 그렇다면 다른 버튼이 애니메이션 될 수 있음을 의미합니다. 따라서 완료된 이벤트는 다음 버튼을 사용하여 애니메이션을 다시 실행합니다.

public void startbtn_Click(object sender, RoutedEventArgs e) 
{ 
    engine.resetSequence(); // Start from sequence 0 
    // Animate first button 
    animate(engine.animate()); 
} 


private void animate(int index) 
{ 

    // Storyboard for each button is in the format of ButtonAnimation_INDEX where INDEX is 1, 2, 3 or 4 
     Storyboard btnAnimation = (Storyboard)this.Resources["ButtonAnimation_" + index]; 
     // Added completed event function handler 
     btnAnimation.Completed += btnAnimation_Completed; 
     if (btnAnimation != null) 
     { 
      btnAnimation.Begin(); 
     } 
} 


void btnAnimation_Completed(object sender, EventArgs e) 
{ 
    // If another button can be animated in the sequence 
    if (engine.CurrentSequence() < engine.getCurrentLevel()) 
    { 
     // Increment the sequence position 
     engine.nextSequence(); 
     // Run the animation with the next button 
     animate(engine.animate()); 
    } 
} 
관련 문제