0
我遇到了一個問題,我的菜單中某個面板的菜單項正在被裁剪,所以這些東西並不在面板的頂部。一切正常,你只是看不到那個點以下的東西。當我檢查這個面板是用這個代碼的時候XNA 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個裁掉所有的除了一個部分,依此類推。當我不檢查它時(我只是使用第二行),那麼第一個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);
內部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);
內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);
如果您有什麼需要,請讓我知道!
此外,經過一些測試後,我認爲錯誤發生在菜單初始化的某處,或者在繪圖過程中。我只是無法弄清楚究竟是什麼錯誤。 – Halleflux
好吧,我想我知道問題是什麼,我只是不知道如何解決它。所選面板右側沒有繪製任何東西,或者在下面。然而,任何高於它的是。 – Halleflux
問題解決了。我只需要畫一點不同。 – Halleflux