2013-03-09 2 views
0

주의 :이 질문은 이 아닌입니다.Winform 및 XNA 게임을 병렬로 실행

XNA 게임 창을 stop pausing its execution인데있는 동안 dragged or resized으로 만드는 방법을 생각했습니다. 대부분의 경우 네트워크 연결이 중단되어 게임 서버와의 동기화가 끊어지기 때문입니다. 경계없는 게임 창과 시각적 컨테이너 인 winform을 사용하면이 트릭을 수행 할 수 있습니다. 문제는 사용자가 위조 된 게임 창 테두리 (실제로 winform)의 크기를 조정하면 게임 창에서이를 확인하고 winform의 클라이언트 영역에 맞게 경계를 조정합니다. 간단하지만, 나는 그 일을하는 데 어려움을 겪고있다.

게임 창과 winform은 서로의 존재를 인식해야하므로 포커스가 winform에 있으면 즉시 게임 창으로 이동하고 게임 창의 크기가 winform에 맞게 조정되거나 크기 변경을 위해 폴링되거나 어쩌면 사건이 일어날 때까지 기다릴 수도 있습니다. 윈도우 핸들 교환이 필요합니다.

this very recent question이 있는데, 몇 시간 전에 두 개의 WinForms를 함께 실행하는 것에 대해 물었습니다. 당신이 나를 도울 수 있습니다 희망, 따라서이 문제에 우리 모두 :)


도움 :

XNA How to Render and Update while resizing

XNA Is Running Slow when focus is removed

답변

0

가 그렇게 어렵지 않다 밝혀, 게임에서 리소스를 훔치거나 자발적인 지연 (약간 눈에 띄는)을 유발하고 게임을 완벽하게 작동시키는 등의 바람직하지 않은 부작용을 초래할 수 있지만 다소 시간이 걸릴 수 있습니다.

내가 수행 한 작업은 새 Form으로 만들어지고 ResizeEnd 이벤트에 이벤트 처리기가 할당되었습니다. 이벤트 처리기는 public static Rectangle fakeWindowRectForm.RectangleToScreen() 메서드를 사용하여 계산 된 위조 창 클라이언트 영역의 새 사각형으로 설정합니다. 여기

는 일부 코드 조각입니다 :

static void Main(string[] args) 
{ 
    System.Windows.Forms.Form f = new System.Windows.Forms.Form(); 
    f.ClientSize = new System.Drawing.Size(800, 600); 
    f.TransparencyKey = f.BackColor; 
    ((Action)(() => System.Windows.Forms.Application.Run(f))).BeginInvoke(
                   null, null); 

    using (Game1 game = new Game1()) 
    { 
     f.ResizeEnd += new EventHandler(game.f_LocationChanged); 
     game.Run(); 
    } 
} 

public class Game1 : Microsoft.Xna.Framework.Game 
{ 
    public static Rectangle windowRect; 

    /* ... */ 

    protected override void Update(GameTime gameTime) 
    { 
     if (windowRect.X != this.Window.ClientBounds.X || 
      windowRect.Y != this.Window.ClientBounds.Y || 
      windowRect.Width != this.Window.ClientBounds.Width || 
      windowRect.Height != this.Window.ClientBounds.Height) 
     { 
      // this method sets the game window size, but not location 
      InitGraphicsMode(windowRect.Width, windowRect.Height, 
       this.graphics.IsFullScreen); 

      var win = System.Windows.Forms.Control.FromHandle(
      this.Window.Handle) as 
       System.Windows.Forms.Form; 

      win.SetBounds(windowRect.X, 
          windowRect.Y, 
          windowRect.Width, 
          windowRect.Height); 
      win.Activate(); 
     } 
    } 


    public void f_LocationChanged(object sender, EventArgs e) 
    { 
     var FakeWindow = sender as System.Windows.Forms.Form; 

     var drawClientArea = FakeWindow.RectangleToScreen(
           FakeWindow.ClientRectangle); 
     windowRect = new Rectangle(
        drawClientArea.X, 
        drawClientArea.Y, 
        drawClientArea.Width, 
        drawClientArea.Height); 
    } 

} 

구현이 잘못된 모든 주위 끔찍한 및 수도 있지만 게임이 일부 프레임을 삭제 가짜 폼의 크기를 조정하는 경우에도, 게임에서 모든 자원을 훔치는없이 작동하지만, 멈추지 않는다.

나는 그것을 시험해 보았지만 효과가 있었지만, 주로 과학을위한 것이었고, 나는이 접근법을 조만간 사용할 생각이 없다. 어쩌면 내가 정말로 필요할 때.