2013-08-09 2 views
0

내 프로그램에 문제가 있습니다. 나는 화면이 화면의 다른 모든 것을 어떻게 차지하는지 이해하지 못합니다. 세부 정보, 내 코드는 다음과 같습니다 : 당신이 hitbox에서 (흰색 화면)에서 볼 수 있듯이왜 그림이 스프라이트 배치에서 다른 그림보다 먼저 나타 납니까?

public override void Draw(GameTime gameTime, SpriteBatch spriteBatch) 
    { 
     spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, null, null, null, null, cam.get_transformation(GestionEcran.GraphicsDevice)); 

     //Draw the background 
     decor.Draw(spriteBatch, gameTime, 255); 

     //Draw the players 
     Player2.Draw(spriteBatch, gameTime); 
     Player1.Draw(spriteBatch, gameTime); 

     //Draw the foreground 
     decor.DrawPremierPlan(spriteBatch, gameTime, 70); 


     if (aPlayerisWinning== true) 
     { 
      //THIS LINE "HITBOX" IS APPEARING BEFORE PLAYERPORTRAIT!!!!!!!!!!!!!! 
      spriteBatch.Draw(hitBox, new Rectangle(0, 0, 500,500), new Color(255, 255, 255, 255)); 
      spriteBatch.Draw(PlayerPortrait, new Rectangle(0,0,500,500), new Color(255, 255, 255, 255)); 
     } 
     spriteBatch.End(); 

     // USED FOR ADDITIVE BLENDING 

     spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Additive, null, null, null, null, cam.get_transformation(GestionEcran.GraphicsDevice)); 
     { 
      Player1.DrawEffects(spriteBatch,gameTime); 
      Player2.DrawEffects(spriteBatch,gameTime); 
     } 
     spriteBatch.End(); 

는 PlayerPortrait 뒤에 표시해야하지만 작동하지 않습니다. 흰색 화면에는 다른 모든 도면이 표시됩니다.

의견이 있으십니까? Thx.

편집 : SpriteSortMode로 아무 것도 변경되지 않습니다. BacktoFront, FrontToBack 및 Texture가 겹쳐져 있습니다. 즉시 및 Deffered 잘 작동하지만 흰색 화면과 동일한 문제가 있습니다. 첫 번째 대답의 링크에서 deffered는 Draw와 동일한 순서로 모든 스프라이트를 하나의 배치로 그립니다. 그렇다면 마지막 전화가 걸리기 전에 왜 두 번째 전화가 먼저 나올까요?

답변

1

각 드로우의 알파를 가지고 해답을 발견했습니다. 내가 원하는 효과를 내고 문제를 우회합니다.

해결 방법 2 : 투명도에서 재생할 알파 채널을 가지고 노는 경우 화면을 투명하게 만들기 위해 RGB도 조작해야합니다. 나는 몰랐다.

2

다른 SpriteSortMode 열거자를 확인하십시오.

BackToFrontFrontToBack을 사용하여 그리기 순서를 변경할 수 있습니다. 이는 Deferred 모드의 변형입니다. TextureDeferred의 또 다른 버전이며 텍스처를 정렬하여 성능도 향상시킵니다.

+0

고맙지 만 변경된 사항이 없으므로 마지막 호출에서 두 번째 호출이 마지막 호출 전에 나타납니다. – Pilispring

관련 문제