Time for action – customizing the Initialize() method
Add the following
code snippet to the Ini
tialize()
method before base:Initialize()
:
playerScore = 0;
What just happened?
The only initialization we need to do is set the player's score to zero. Even this initialization is not strictly necessary, as zero is the default value for an int
variable, but it is a good practice not to assume that this work will have been done for us.
Note
Initialize() versus LoadContent()
In practice, much of a game's initialization actually takes place in the LoadContent()
method
, which we will discuss next, instead of the Initialize()
method. This is because many times the items we want to initialize require content assets in order to be properly created. One common use for the Initialize()
method is to set the initial display area (resolution) and switch into full screen mode.