Difference between revisions of "Game Programming Class4"
(→Game Service) |
|||
Line 2: | Line 2: | ||
About components [http://msdn.microsoft.com/en-us/library/bb203873.aspx Application Overview] | About components [http://msdn.microsoft.com/en-us/library/bb203873.aspx Application Overview] | ||
− | Game Components are reusable and easy to add to a game | + | Game Components are reusable and easy to add to a game. |
* GameComponent Class | * GameComponent Class | ||
Line 10: | Line 10: | ||
==Game Service== | ==Game Service== | ||
− | A game service is a game component that uses | + | A game service is a game component that uses an interface to enforce a singleton pattern and make a single instance of a game component accessible to all other components. It's a nice mechanism to maintain a loose coupling between components. |
A singleton is a class that only allows a single instance of the class to be created. A game service is not a true singleton as it uses a unique interface to identify and expose it at the game level. | A singleton is a class that only allows a single instance of the class to be created. A game service is not a true singleton as it uses a unique interface to identify and expose it at the game level. | ||
Line 26: | Line 26: | ||
===Console Class=== | ===Console Class=== | ||
− | Separate IntroGameLibrary Project to help Encapsulate Reusable Code. IntroConsole.zip | + | Separate IntroGameLibrary Project to help Encapsulate Reusable Code. |
− | + | * IntroConsole.zip | |
+ | * IntroGameLibrary.zip | ||
− | + | IntroGameLibrary/GameConsole.cs | |
− | To | + | To add the Component to the Game we make an declare in the game class. Then we need to add the component to the Game Components Collection. |
Line 54: | Line 55: | ||
Bonus | Bonus | ||
− | *Create your own game service and use it in an xna project | + | * Create your own game service and use it in an xna project |
Revision as of 07:51, 16 February 2009
Game Components
About components Application Overview
Game Components are reusable and easy to add to a game.
- GameComponent Class
- DrawGameComponent Class
http://blogs.msdn.com/xna/archive/2006/08/31/734204.aspx
Game Service
A game service is a game component that uses an interface to enforce a singleton pattern and make a single instance of a game component accessible to all other components. It's a nice mechanism to maintain a loose coupling between components.
A singleton is a class that only allows a single instance of the class to be created. A game service is not a true singleton as it uses a unique interface to identify and expose it at the game level.
A game service is a built in mechanism that allows a game to create and manage a single instance of a component ans allows other components access to the service.
Good candidates for a game service are.
- InputHandler
- GameConsole
- Profiling Service
- Scoreboard
Microsoft has added the
Console Class
Separate IntroGameLibrary Project to help Encapsulate Reusable Code.
- IntroConsole.zip
- IntroGameLibrary.zip
IntroGameLibrary/GameConsole.cs To add the Component to the Game we make an declare in the game class. Then we need to add the component to the Game Components Collection.
<csharp>
GameConsole gameConsole;
public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content";
gameConsole = new GameConsole(this); this.Components.Add(gameConsole); }
</csharp>
IntroConsole/Game1.cs
Homework
- Use the fps component to create a baseline log
- Convert Project 3 to use the inputHandler service
Bonus
- Create your own game service and use it in an xna project