3
votes

First post, first year programmer so go easy please.

When drawing a sprite in monogame, does anybody know how to make it stretch into the full screen?

For example I have my start screen appear but it doesnt stretch into the full screen (cause i have my window maximized when it opens). I've got "spriteBatch.Draw(startScreen, Vector2.Zero, null, Color.White);"

the null represents the rectangle property. does anybdoy know a word to replace null so that will stretch it?

This is in my load content for the texture:

startScreen = Content.Load<Texture2D>("Images/startGameSplash");

Then this is where I call it in my Draw Method:

protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            switch (gameState)
            { 
                case GameState.StartScreen:
                    //draw the start screen
                    spriteBatch.Begin();
                    spriteBatch.Draw(startScreen, Vector2.Zero, null, Color.White);
                    //Drawing each rocket with another foreach
                    spriteBatch.End();
                    break;

                case GameState.Running:
                    spriteBatch.Begin();
                    tank.Draw(spriteBatch);

                    foreach (BaseRocket shot in rocket) {
                        shot.Draw(spriteBatch);
                    }
                    spriteBatch.End();
                    break;

                case GameState.EndScreen:
                    spriteBatch.Begin();
                    spriteBatch.Draw(endScreen, Vector2.Zero, null, Color.White);
                    spriteBatch.End();
                    break;

                default:
                    break;

            }
            base.Draw(gameTime);

        }
    }
}

Thanks,

1
Can you show more codes ? - Raptor
Done, do you need more? - Brandon M
fine for now. If you read the documentation / source code of SpriteBatch class of monogame, you will see this: public void Draw (Texture2D texture, Rectangle rectangle, Color color), which 2nd parameter is the size of the sprite. Assign the screen size rectangle to the parameter, and your sprite should fill the screen. - Raptor
Got it to work thank you. I used spriteBatch.Draw(startScreen, new Rectangle(0,0,GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height), Color.White); - Brandon M
good to know the code is working now. i formatted the comment into answer below. please accept it if you found it useful, thanks. - Raptor

1 Answers

3
votes

From the source code / documentation of SpriteBatch class of MonoGame, there is a Draw function which accepts size as 2nd parameter:

public void Draw (Texture2D texture, Rectangle rectangle, Color color)

Assign the screen size rectangle to the parameter, and your sprite should fill the screen.