I am a noob at programming but before we start please answer me why does update execute more than once an explain it like i am a dummy.
Anyways so i am trying to make this code run only once because as of now it executes it more than once.
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
// TODO: Add your update logic here
button = Mouse.GetState();
if (button.X < buttonPosition.X || button.Y < buttonPosition.Y || button.X > buttonPosition.X + font1.MeasureString(buttonText).X ||
button.Y > buttonPosition.Y + font1.MeasureString(buttonText).Y)
buttonColour = new Color(0, 0, 0);//if the mouse if not hovering over the font it stays that color
else
buttonColour = new Color(0, 255, 255);//changes to this color if it is hovering over text
if(button.LeftButton==ButtonState.Pressed)
display = (display == false) ? true : false; //if display = true it will set it to false
//if false then it will set it to false
}
This is the Draw method if you need it.
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin();
spriteBatch.DrawString(font1, buttonText, buttonPosition, buttonColour); //this is the button leftbutton has to click to trigger the below if statement.
if (display)
spriteBatch.DrawString(font1, text, position, Color.White);
spriteBatch.End(); //it will draw this when leftbutton clicks the above button
// TODO: Add your drawing code here
base.Draw(gameTime);
}