在我目前正在處理的遊戲中,我有一個播放按鈕,其中有一個Vector2
,一個Rectangle
和一個Texture2D
。但不知何故,當我運行遊戲時,播放按鈕是不可見的,但它仍然對鼠標碰撞/檢測作出反應。
這是我的代碼:矩形使Texture2D隱形
Texture2D buttonPlay;
Rectangle buttonPlayRect;
Vector2 buttonPlayPos;
Point mousePosition;
int resolutionX = ScreenManager.GraphicsDeviceMgr.PreferredBackBufferWidth;
int resolutionY = ScreenManager.GraphicsDeviceMgr.PreferredBackBufferHeight;
public void Initialize()
{
buttonPlayPos = new Vector2(resolutionX/2 - 64, resolutionY/2 - 64);
}
public override void LoadAssets()
{
buttonOptionsPos = new Vector2(resolutionX/2 - 64, resolutionY/2);
backgroundTile = ScreenManager.ContentMgr.Load<Texture2D>("Menu/background");
buttonOptions = ScreenManager.ContentMgr.Load<Texture2D>("Menu/optionsButton");
buttonPlay = ScreenManager.ContentMgr.Load<Texture2D>("Menu/playButton");
buttonPlayRect = new Rectangle((int)buttonPlayPos.X, (int)buttonPlayPos.Y, buttonPlay.Width, buttonPlay.Height);
base.LoadAssets();
}
public override void Update(Microsoft.Xna.Framework.GameTime gameTime)
{
MouseState mState = Mouse.GetState();
mousePosition = new Point(mState.X, mState.Y);
base.Update(gameTime);
}
public override void Draw(Microsoft.Xna.Framework.GameTime gameTime)
{
for (int x = 0; x < 10; x++)
{
for (int y = 0; y < 10; y++)
{
ScreenManager.Sprites.Draw(backgroundTile, new Vector2(tileWidth * x, tileHeight * y), Color.White);
}
}
ScreenManager.Sprites.Draw(buttonPlay, buttonPlayPos, buttonPlayRect, Color.White);
ScreenManager.Sprites.Draw(buttonOptions, buttonOptionsPos, Color.White);
if (buttonPlayRect.Contains(mousePosition))
{
}
base.Draw(gameTime);
}
}
我有這個問題與藏漢其他項目的同時,是什麼讓Texture2D
不會出現?提前致謝!
'buttonOptions'顯示嗎? – Robb
是的,它確實但我不用'buttonOptionsRect'繪製它。 – QuackTheDuck