X hits on this document

246 views

0 shares

0 downloads

0 comments

24 / 102

}

Note: From this point forward, whenever creating a new class, always change its namespace to "CatapultGame".

40.

Add the following class variables to be used later for loading the background image:

C#

Texture2D background;

41.

Define a class constructor as follows:

C#

public BackgroundScreen()

{

   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.

42.

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:

C#

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.

43.

Add custom drawing logic to the class by overriding the Draw method:

C#

public override void Draw(GameTime gameTime)

{

SpriteBatch spriteBatch = ScreenManager.SpriteBatch;

spriteBatch.Begin();

// Draw Background

spriteBatch.Draw(background, new Vector2(0, 0),

new Color(255, 255, 255, TransitionAlpha));

spriteBatch.End();

}

Page | 24

Document info
Document views246
Page views246
Page last viewedTue Dec 06 16:54:34 UTC 2016
Pages102
Paragraphs3115
Words17333

Comments