MONOGAME: Två problem med min pause metod
Tja!
Har två problem och båda handlar om min pause metod, alltså vill jag pausa spelet.
Första problemet är att bollen och paddle inte kan röra sig, efter att jag klickat P för att återuppta spelet.
Andra problemet är att min LEVEL text och blocken försvinner när jag klickar på P. Istället vill jag att de ska ritas på det andra och inte göra så det andra försvinner under.
Specifika del som behöver fixas:
else if (paused == true)
{
SpriteBatch.Draw(pausemenu_texture, pausemenu_rect, Color.White);
}
All kod som behövs på första problemet:
protected override void Initialize()
{
paddle_speed.X = 6f;
ball_speed.Y = 7f;
ball_speed.X = 1f;
base.Initialize();
}
void Pause()
{
if (paused == true)
{
paddle_speed.X = 0f;
ball_speed.Y = 0f;
ball_speed.X = 0f;
}
}
void KeyboardMouse()
{
KeyboardState ks = Keyboard.GetState();
if (ks.IsKeyDown(Keys.Left))
{
paddle_rect.X -= (int)paddle_speed.X;
holdingleft = true;
}
else if (ks.IsKeyDown(Keys.Right))
{
paddle_rect.X += (int)paddle_speed.X;
holdingright = true;
}
else if (ks.Equals(new KeyboardState()))
{
resetballspeed = true;
}
else if (ks.IsKeyDown(Keys.P) && Previousks.IsKeyUp(Keys.P))
{
if (paused == false)
paused = true;
else if (paused == true)
paused = false;
}
//BOLLEN RÖR SIG OM MAN KLICKAR SPACE
else if (ks.IsKeyDown(Keys.Space))
{
Start = true;
}
else if (ks.IsKeyDown(Keys.R))
{
ResetButton();
}
Previousks = ks;
}
Specifika del som behöver fixas:
void Pause()
{
if (paused == true)
{
paddle_speed.X = 0f;
ball_speed.Y = 0f;
ball_speed.X = 0f;
}
}
All kod som behövs på andra problemet:
pausemenu_texture = Content.Load<Texture2D>("Pics/PauseMenu");
pausemenu_rect = new Rectangle((Window.ClientBounds.Width / 2) - (pausemenu_texture.Width / 2), ((Window.ClientBounds.Height / 2) - pausemenu_texture.Height / 2), pausemenu_texture.Width, pausemenu_texture.Height);
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.Black);
spriteBatch.Begin();
//SÅLÄNGE LIV ÄR STÖRRE ÄN 0 SÅ GÖRS DET HÄR
if (lives > 0)
{
spriteBatch.Draw(ball_texture, ball_rect, Color.White);
spriteBatch.Draw(paddle_texture, paddle_rect, Color.White);
spriteBatch.DrawString(spritefont, "Lives left: " + lives, new Vector2(2, 0), Color.White);
spriteBatch.DrawString(spritefont, "Points: " + points, new Vector2(350, 0), Color.White);
spriteBatch.DrawString(spritefont, "Highscore: " + highscore, new Vector2(652, 0), Color.White);
spriteBatch.DrawString(spritefont, "Timer: " + seconds, new Vector2(350, 600), Color.White);
if (level == 1)
{
if (block.Count == 14 && block2.Count == 14)
{
spriteBatch.DrawString(spritefont2, "LEVEL " + level, new Vector2(252, 400), Color.White);
}
foreach (Rectangle g in block)
{
spriteBatch.Draw(block_texture, g, Color.LimeGreen);
}
foreach (Rectangle r in block2)
{
spriteBatch.Draw(block_texture, r, Color.IndianRed);
}
}
else if (level == 2)
{
if (block3.Count == 18 && block4.Count == 27)
{
spriteBatch.DrawString(spritefont2, "LEVEL " + level, new Vector2(246, 400), Color.White);
}
foreach (Rectangle b in block3)
{
spriteBatch.Draw(block_texture, b, Color.CornflowerBlue);
}
foreach (Rectangle y in block4)
{
spriteBatch.Draw(block_texture, y, Color.Yellow);
}
}
else if (level == 3)
{
if (block5.Count == 36 && block6.Count == 18)
{
spriteBatch.DrawString(spritefont2, "LEVEL " + level, new Vector2(246, 400), Color.White);
}
foreach (Rectangle o in block5)
{
spriteBatch.Draw(block_texture, o, Color.Orange);
}
foreach (Rectangle p in block6)
{
spriteBatch.Draw(block_texture, p, Color.HotPink);
}
}
else if (paused == true)
{
spriteBatch.Draw(pausemenu_texture, pausemenu_rect, Color.White);
}
else if (block5.Count == 0 && block6.Count == 0)
{
//visa en vinnarbild
}
}
//OM LIV ÄR 0 TAS ALLT ANNAT BORT OCH GAMEOVER BILDEN KOMMER FRAM
else if (lives == 0)
{
spriteBatch.Draw(gameover_texture, gameover_rect, Color.White);
}
spriteBatch.End();
base.Draw(gameTime);
}
HÄR ÄR BILDEN TILL PROBLEM 2:
http://imgur.com/a/MwZQj