Note: From this point forward, whenever creating a new class, always change its namespace to "CatapultGame".
Add the following class variables to be used later for loading the background image:
Define a class constructor as follows:
TransitionOnTime = TimeSpan.FromSeconds(0.0);
TransitionOffTime = TimeSpan.FromSeconds(0.5);
The above code simply sets values to some of the properties derived from GameScreen, which control how the screen is brought in and out of view.
The GameScreen class defines some core game functionality matching the four states described in the exercise preface: LoadContent, Update, Draw and UnloadContent. Override the base class’s LoadContent functionality:
public override void LoadContent()
background = Load<Texture2D>("Textures/Backgrounds/title_screen");
This code loads the game’s background image from the appropriate resource, according to its path in the content project.
Add custom drawing logic to the class by overriding the Draw method:
public override void Draw(GameTime gameTime)
SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
// Draw Background
spriteBatch.Draw(background, new Vector2(0, 0),
new Color(255, 255, 255, TransitionAlpha));
Page | 24