Halleflux
Halleflux

Reputation: 35

XNA Texture2D cropping bug

I am having an issue where my menu an menu items for a panel are being cropped, so the stuff doesn't go below the top of the panel. Everything works fine, you just can't see the stuff below that point. When I check where that panel is with this code

if (Position.X <= 400)
    panelMenu.Initialize(TestPanelMenuTexture, new Vector2(700, 200), Item1, Item2, Item3, Item4);
else
    panelMenu.Initialize(TestPanelMenuTexture, new Vector2(100, 200), Item1, Item2, Item3, Item4);

the first 4 crop off the entire menu, then the next 8 crop off all but one section, and so on. When I don't check it (I just use line 2), then the first 8 cut off everything, the next 8 cut off all but one section, and so on. (Side note: each section is 100 pixels high.)

Here is the code used to initialize each panel, and the menu and menu items:

for (int i = 0; i <= 7; i++)
{
    for (int q = 0; q <= 7; q++)
    {
        Panel Panel = new Panel();
        Panel.Initialize(TestTextureStill, TestTextureHover, TestTextureActive, new Vector2 (q * 100 + 50, i * 100 + 50), MenuTexture, menuItem1, menuItem2, menuItem3, menuItem4);
        Panels[i, q] = Panel;
    }
}

Panel menu

if (Position.X <= 400)
    panelMenu.Initialize(TestPanelMenuTexture, new Vector2(700, 200), Item1, Item2, Item3, Item4);
else
    panelMenu.Initialize(TestPanelMenuTexture, new Vector2(100, 200), Item1, Item2, Item3, Item4);

Here is the drawing code:

GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin();
for (int i = 0; i <= 7; i++)
{
    for (int q = 0; q <= 7; q++)
        Panels[i, q].Draw(spriteBatch);
}
spriteBatch.End();
base.Draw(gameTime);

Inside Panel.Draw()

if (selected)
    panelMenu.Draw(spriteBatch);
spriteBatch.Draw(PanelTextureCurrent, Position, null, Color.White, 0f, new Vector2(Width / 2, Height / 2), 1f, SpriteEffects.None, 0f);

Inside PanelMenu.Draw()

spriteBatch.Draw(PanelMenuTexture, Position, null, Color.White, 0f, new Vector2(Width / 2, Height / 2), 1f, SpriteEffects.None, 0f);
spriteBatch.Draw(Item1.CurrentTexture, new Vector2(Position.X, 50), null, Color.White, 0f, new Vector2(WidthMI1 / 2, HeightMI1 / 2), 1f, SpriteEffects.None, 0f);
spriteBatch.Draw(Item2.CurrentTexture, new Vector2(Position.X, 150), null, Color.White, 0f, new Vector2(WidthMI2 / 2, HeightMI2 / 2), 1f, SpriteEffects.None, 0f);
spriteBatch.Draw(Item3.CurrentTexture, new Vector2(Position.X, 250), null, Color.White, 0f, new Vector2(WidthMI3 / 2, HeightMI3 / 2), 1f, SpriteEffects.None, 0f);
spriteBatch.Draw(Item4.CurrentTexture, new Vector2(Position.X, 350), null, Color.White, 0f, new Vector2(WidthMI4 / 2, HeightMI4 / 2), 1f, SpriteEffects.None, 0f);

If you need ANYTHING else, please let me know!

Upvotes: 0

Views: 135

Answers (1)

Halleflux
Halleflux

Reputation: 35

Move the drawing of the menu&items to after all the panels have been drawn. This is because the panels overlapped the menu, causing it to vanish.

Upvotes: 1

Related Questions