2013-04-21 5 views
0

XNA 용 GUI 라이브러리에서 작업 중이므로 해결 방법을 찾을 수없는 문제가 있습니다. rendertargets를 많이 사용하고 있는데, 그 자체로 짜증나지만, 정말 이상하고 구체적인 이슈가 있습니다.게임이 최소화 될 때 RenderTarget 컨텐츠가 변경됩니다.

내 ProgressBar 클래스에서 요소가 유효하고 객체 크기가 변경되면 개별 구성 요소를 그립니다. 객체가 Validated이지만 객체 크기가 변경되지 않은 경우 채워진 rendertargets를 텍스처로 사용하여 버퍼 텍스쳐 (다시 렌더링 타겟)에 최종 제품을 그립니다. 이제 응용 프로그램을 최소화하고 탭을 다시 누를 때마다 진행 막대의 배경 레이어에 위에 줄무늬가있는 질감이 인쇄됩니다. 렌더 타겟은 내용을 유지하도록 설정되어 있으며 정확한 렌더 타겟이 설정되어 있는지 확인했습니다. 또한 graphicsDevice ("실제 그리기"줄 바로 아래)를 지우는 것은 아무 것도하지 않습니다. 왜?

그래서 기본적으로 게임은 해당 지역의 스크린 샷을 만들어 내 텍스처에 그립니다. 도대체 뭐야? 이 내용이있을 때마다이 문제에 대한 해결책은 렌더가 콘텐츠를 유지할 수 있도록, 전체 빌어 먹을 일을 다시 그릴 것을 보인다

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using Microsoft.Xna.Framework; 
using Microsoft.Xna.Framework.Graphics; 
using Microsoft.Xna.Framework.Input; 
namespace PixLib 
{ 
    public class ProgressBar : UIElement 
    { 
     private float stripeThickness = 5; 
     private float stripeGapFactor = 3f; 
     private float animationSpeed = 1f; 
     private float at = 0; 
     private RenderTarget2D stripesBg, stripes; 
     private Coordinate2 lastSize; 
     protected override Coordinate2 InnerArea 
     { 
      get { return Coordinate2.Zero; } 
     } 
     protected Color color; 
     public Color Color 
     { 
      get 
      { 
       return color; 
      } 
      set 
      { 
       color = value; 
       Invalidate(); 
      } 
     } 
     protected float value; 
     public float Value 
     { 
      get 
      { 
       return value; 
      } 
      set 
      { 
       float t = Math.Min(1, Math.Max(0, value)); 
       if (t != this.value) 
       { 
        this.value = t; 
        Invalidate(); 
       } 

      } 
     } 
     public ProgressBar(string name,Color color, Rectangle elementRect, bool localPos = true) 
      : base(name, elementRect, localPos) 
     { 
      lastSize = new Coordinate2(); 
      this.color = color; 
      value = 0; 
      at = 0; 
     } 
     protected override void OnUpdate(MouseState mouseState, KeyboardState keyboardState) 
     { 

     } 
     protected override void OnInit() 
     { 

     } 
     protected override void Redraw(SpriteBatch spriteBatch) 
     { 

      if (lastSize.X != Width || lastSize.Y != Height) 
      { 

       Console.WriteLine("Redrawing Progressbar"); 
       //redraw textures! 
       stripesBg = new RenderTarget2D(graphicsManager.GraphicsDevice, Width, Height, false, graphicsManager.GraphicsDevice.DisplayMode.Format, DepthFormat.Depth24, 1, RenderTargetUsage.PreserveContents); 
       stripes = new RenderTarget2D(graphicsManager.GraphicsDevice, Width, Height * 2, false, graphicsManager.GraphicsDevice.DisplayMode.Format, DepthFormat.Depth24, 1, RenderTargetUsage.PreserveContents); 

       spriteBatch.Begin(); 
       spriteBatch.Draw(pixel, new Rectangle(0, 0, Width, Height), Color.White); 
       spriteBatch.End(); 

       SetRenderTarget(stripesBg); 
       spriteBatch.Begin(); 
       spriteBatch.Draw(pixel, new Rectangle(0, 0, Width, Height), Color.White); 
       spriteBatch.End(); 

       /*SetRenderTarget(border); 
       spriteBatch.Begin(); 
       int si = (int)(stripeThickness*0.5f + 0.5f); 
       DrawLine(new Coordinate2(si, 0), new Coordinate2(Width, 0), spriteBatch, Color.White, si); 
       DrawLine(new Coordinate2(si, Height - si), new Coordinate2(Width, Height - si), spriteBatch, Color.White, si); 
       DrawLine(new Coordinate2(si, 0), new Coordinate2(si, Height), spriteBatch, Color.White, si); 
       DrawLine(new Coordinate2(Width, 0), new Coordinate2(Width, Height - si), spriteBatch, Color.White, si); 
       spriteBatch.End();*/ 

       SetRenderTarget(stripes); 
       spriteBatch.Begin(); 
       int fy = (int)(stripeThickness +0.5f); 
       int s = (Height + fy) * 2; 
       int fx = -s; 
       at = 0; 
       while (fx < Width + stripeThickness * stripeGapFactor) 
       { 

        DrawLine(new Coordinate2(fx, -fy), new Coordinate2(fx+s, s-fy), spriteBatch, Color.White, stripeThickness); 
        fx += (int)(stripeThickness * stripeGapFactor); 
       } 
       spriteBatch.End(); 


       SetRenderTarget(null); 


       lastSize.X = Width; 
       lastSize.Y = Height; 
      } 

      //actual drawing 
      spriteBatch.Begin(); 
      spriteBatch.Draw(pixel, SizeRect, Darken(color, 2)); 
      int cv = (int)(Value * Width + 0.5f); 
      spriteBatch.Draw(stripesBg, new Rectangle(cv - Width, 0, Width, Height), Darken(Color)); 
      graphicsManager.GraphicsDevice.Clear(Color.Transparent); 
      spriteBatch.Draw(stripes, new Rectangle(cv - Width, -(int)(at + 0.5f), Width, Height * 2), color); 
      spriteBatch.End(); 

      at += animationSpeed; 
      if (at >= Height) 
       at -= Height - (int)(stripeThickness + .5f); 
     } 
    } 
} 

답변

0

자 : 여기

는 ProgressBar의 코드입니다 잃어버린.

if (lastSize.X != Width || lastSize.Y != Height || stripesBg.IsContentLost || stripes.IsContentLost) 
      { 

       Console.WriteLine("Redrawing Progressbar"); 
       //redraw textures! 
       //stripesBg = new RenderTarget2D(graphicsManager.GraphicsDevice, Width, Height, false, graphicsManager.GraphicsDevice.DisplayMode.Format, DepthFormat.Depth24, 1, RenderTargetUsage.PreserveContents); 
       //stripes = new RenderTarget2D(graphicsManager.GraphicsDevice, Width, Height * 2, false, graphicsManager.GraphicsDevice.DisplayMode.Format, DepthFormat.Depth24, 1, RenderTargetUsage.PreserveContents); 
       stripesBg = new RenderTarget2D(graphicsManager.GraphicsDevice, Width, Height); 
       stripes = new RenderTarget2D(graphicsManager.GraphicsDevice, Width, Height * 2); 
[...] 
관련 문제