2017-08-28 111 views
0

試圖在Xna中創建遊戲,但我偶然發現了一個我似乎無法弄清楚的問題。Xna菜單項透明

我想要做的是在屏幕頂部繪製一個菜單,並顯示出來。但我有一個奇怪的問題。 所有的菜單項都是阿爾法,即使我指定的東西是阿爾法的唯一的地方是菜單的背景,有什麼明顯的,我在這裏失蹤?

enter image description here

public static void draw(SpriteBatch sb,SpriteFont font,GraphicsDevice gd) 
    { 
     foreach (string item in menuItems) 
     { 
      MouseState ms = Mouse.GetState(); 
      rect.drawRectangle(gd, sb, new Rectangle(0, 0, gd.Viewport.Width, 35), new Color(0.25f, 0.25f, 0.25f, 0.6f)); 
      if((ms.X > startPos && ms.X < startPos + (int)font.MeasureString(item).X) && (ms.Y > 10 && ms.Y < 30)) 
      { 
       if(ms.LeftButton != ButtonState.Pressed) 
       { 
        sb.DrawString(font, item, new Vector2(startPos, 10), Color.Black); 
        sb.DrawString(font, item, new Vector2(startPos + 1, 11), Color.Gray); 
       }else 
       { 
        sb.DrawString(font, item, new Vector2(startPos, 10), Color.Black); 
        sb.DrawString(font, item, new Vector2(startPos + 1, 11), Color.DarkGray); 
       } 

      } 
      else 
      { 
       sb.DrawString(font, item, new Vector2(startPos, 10), Color.Black); 
       sb.DrawString(font, item, new Vector2(startPos + 1, 11), Color.White); 
      } 

      startPos += (10 + (int)font.MeasureString(item).X); 
     } 
     startPos = 10; 
    } 

RECT類:

public static void drawRectangle(GraphicsDevice graphics,SpriteBatch sb,Rectangle rect,Color color) 
     { 
      Texture2D pixel = new Texture2D(graphics, 1, 1); 
      Color[] colorData = {color}; 
      pixel.SetData<Color>(colorData); 
      sb.Draw(pixel, rect, color); 
     } 

我試圖創建一個新的色彩,不帶alpha,但我得到了相同的結果。

+0

您使用的字體,可能是圖片調整大小,但文本看起來像'Öptions'和'Člose'... –

回答

2

我想通了! 不得不移動

rect.drawRectangle(gd, sb, new Rectangle(0, 0, gd.Viewport.Width, 35), new Color(0.25f, 0.25f, 0.25f,0.6f)); 

在循環之外。