I'm new to XNA and I'm trying to create a simple game menu and I'm using rectangles as menu items. I have the main class which is called Game1.cs and a different class for a rectangle, that is supposed to close the game on click, which is called _exitGame.cs. So far I've got this-
In the main class I initialize a class variable:
_exitGame exitGame;
I load the texture and the rectangle:
exitGame = new _exitGame(Content.Load<Texture2D>("exitGame"), new Rectangle(50, 250,300,50));
I've created a update code for the class:
exitGame.Update(gameTime);
And I draw the rectangle:
exitGame.Draw(spriteBatch);
In my _exitGame class I have this:
class _exitGame
{
Texture2D texture;
Rectangle rectangle;
public _exitGame(Texture2D newTexture, Rectangle newRectangle)
{
texture = newTexture;
rectangle = newRectangle;
}
public void LoadContent()
{
}
public void Update(GameTime gametime)
{
var mouseState = Mouse.GetState();
var mousePosition = new Point(mouseState.X, mouseState.Y);
var recWidth = rectangle.Width;
var recHeight = rectangle.Height;
if (rectangle.Contains(mousePosition))
{
rectangle.Width = 310;
rectangle.Height = 60;
}
else
{
rectangle.Width = 300;
rectangle.Height = 50;
}
}
public void Draw(SpriteBatch spriteBatch)
{
spriteBatch.Draw(texture, rectangle , Color.White);
}
}
So right now what I have is a rectangle that changes its size on mouse hover. Earlier I used code this.Close(); to close the game on keyboard button click but since I can't use it in this situation I'm a bit confused how to achieve this functionality. Any tips on how to do that?