XNA Texture2D裁剪bug

时间:2012-09-02 00:57:46

标签: xna crop texture2d

我遇到的问题是我的菜单正在裁剪面板的菜单项,因此这些东西不会低于面板的顶部。一切正常,你只是看不到那点下面的东西。当我使用此代码检查该面板的位置时

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);

整个菜单中的前4个裁剪,然后除了一个部分之外的下一个8裁剪,依此类推。当我不检查它时(我只使用第2行),然后前8个切断所有内容,接下来的8个除了一个部分之外的所有部分,依此类推。 (旁注:每个部分高100像素。)

以下是用于初始化每个面板以及菜单和菜单项的代码:

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;
    }
}

面板菜单

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);

这是绘图代码:

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);

如果您还需要其他任何内容,请告诉我们!

1 个答案:

答案 0 :(得分:1)

在绘制完所有面板后,将菜单和项目的图形移动到。这是因为面板与菜单重叠,导致它消失。