Reputation: 96
Trying to create a game in Xna but i have stumbled upon a problem that i cannot seem to figure out.
What i'm trying to do is to draw a menu at the top of the screen, and it shows up. But I'm having a weird problem. All of the menu items are alpha even though the only place i specify something to be alpha is the background to the menu, is there something obvious that i'm missing 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 class:
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);
}
I have tried to create a new color with no alpha, but i get the same results.
Upvotes: 0
Views: 53
Reputation: 96
I figured it out! Had to move
rect.drawRectangle(gd, sb, new Rectangle(0, 0, gd.Viewport.Width, 35), new Color(0.25f, 0.25f, 0.25f,0.6f));
Outside the loop.
Upvotes: 2