在我目前正在开发的游戏中,我有一个播放按钮,它有一个Vector2
、一个Rectangle
和一个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
不出现?提前致谢!