This project is read-only.

Usage Overview

A game built using the GdiGaming API is comprised of an instance of the GameEngine component and an instance of the RenderCanvas control, which work together to provide the overall framework of the game. The GameEngine executes a GameScene containing GameObjects, GameBackgrounds, and HudLayers while the RenderCanvas draws the game image buffers and monitors mouse and keyboard input.

The primary component of the GdiGaming API is the GameEngine. The GameEngine componet handles the execution of the primary game loop and performs the following operations on each game loop iteration:
  1. Updates Input
    • This includes updating the GameInput object, calling the OnInput method for each GameObject and HUD element, and testing for/calling the mouse input methods for each object.
  2. Updates Each Background
  3. Updates Each Game Object and Checks Collision
  4. Updates Each HUD Element
  5. Draws Each Background, GameObject, and HUD Element
  6. Updates the Playing Audio
  7. Raises the GameLoop Event for the Containing Form
  8. Waits any Remaining Time in this Frame
  9. Updates the GameTime and Frame Rate
  10. Raises the FrameComplete Event for the Containing Form
  11. Restarts the Game Loop

The GameEngine contains a collection of GameScene objects, and has a CurrentSceneName property. When the containing form loads, it creates instances of the required GameScene objects and adds them to the GameEngine. It then sets the CurrentSceneName on the GameEngine to the game's initial scene.

The GameScene is an abstract class which the developer inherits from in order to create specific scenes for the game. Each scene is simply a named container for a group of backgrounds, game objects, and HUD elements. Individual scenes can represent individual levels in a game, or one scene might contain logic to handle multiple levels. Typically things like the game's startup screen, main game screen, and menu screen would each be individual GameScene classes. The scene will override the Name property to return a unique name, and then will typically override the OnLoad method to setup all necessary scene backgrounds, gameobjects, and data.

The GameObject is an abstract class which the developer inherits from in order to create the interactive elements of a game such as players, enemies, items, and logic-components. The GameObject provides the following overridable methods which allow the developer to implement game-logic:
  • OnCollision
  • OnDraw
  • OnLoad
  • OnInput
  • OnMouseDown
  • OnMouseUp
  • OnUpdate

Each method provides an eventargs reference which contains a reference to the game engine, game time, and possibly other appropriate data according to the method.

So every game will have one instance of a GameEngine component and one instance of a RenderCanvas control added to the main form, and then will define individual GameObject and GameScene classes in order to create all of the game's content.

Asset management is handled by the GdiGaming.AssetManager object on the GameEngine. When you develop your game project, you add a folder to the project called "Assets". All of the game's image and sound files are then added to this folder. You only need to set each file's "Copy to Output Directory" property to "Always", and then the AssetManager will allow your code to refer to any asset by its file name. The asset manager will take care of loading an asset from disk the first time it is requested, and then reusing that asset for subsequent requests. Each GameScene will also cache the assets it uses, so all game-logic should go through the GameEngine.CurrentScene to request assets.

Last edited Dec 29, 2011 at 8:57 PM by ReedKimble, version 4


No comments yet.