Game Development Reference
In-Depth Information
Click here to view code image
public class Localization : Pat-
terns . Singleton < Localization >
That makes the Localization class a singleton that can be globally accessible
anywhere via the Get function, as shown here:
Click here to view code image
Localization .Get().Text("ui_victory");
Several classes in this game are singletons, including GraphicsManager , In-
putManager , PhysicsManager , SoundManager , and GameState . It
might seem like the camera would also be a good candidate for a singleton.
However, the camera isn't a singleton because if the game were a split-screen
game, there could potentially be multiple cameras. In order to try to keep the code
flexible, avoiding assumptions like this that may not be true for every game is typ-
ically a good idea.
Game Class
Game1.cs has the main game class, but it really doesn't have very much code.
Initialize is called when the game is first loaded, and it simply instantiates
some of the singletons. Update and Draw are called every frame, and they just
call Update and Draw on the appropriate singletons. So overall, there really is
not much happening in this file.
One small thing worth noting, though, is the following code snippet from Up-
date :
if (fDeltaTime > 0.1f)
{
fDeltaTime = 0.1f;
}
This forces the minimum frame rate to be 10 FPS. The reason for this is if the
game is paused in the debugger, when it's unpaused the elapsed time might be sev-
eral seconds. By limiting the minimum FPS to 10, it makes sure that there's never
an elapsed time that's so long that the behavior of the game becomes unstable.
Search WWH ::




Custom Search