Cross-Platform Game Programming with gameplay3d/An Overview of the Game Class

Introduction
The  class is the base class for all your games created with the gameplay framework. You are required to extend this class using C++ and to override the core game and lifecycle event methods,  ,  , and. This is where you'll write your code to load the game assets and apply game logic and rendering code. Under the hood, the game class will receive events and act as an abstraction between the running game and the underlying platform layer that is running the game loop and reacting to operating systems.

There are four methods you must implement to get started in writing your own game:

initialize
The  method is called by the gameplay3d framework just before the first frame when the game starts. You’ll add code here load your game assets and create your scene, along with any other one-off initialization code.

finalize
The  method is called by the gameplay3d framework on exiting your game. You'll add code here to clean up any outstanding resources (see ../gameplay3d_Design_Concepts for further details).

update and render
The  and   methods are called once per frame from the game loop implemented in the   for each operating system. This allows you to separate the code between handling updates to your game’s state and rendering your game’s visuals. You can use a variety of built-in classes to help with the game rendering.

Accessing the game instance
The  class can be accessed from anywhere in your game code. It implements a singleton design pattern. Call the static method  to gain access to the instance of your game from any code.

Graphics and audio devices
After your game has started, the underlying graphics and audio devices will automatically initialize. This happens prior to the  method being called and readies any classes that use OpenGL (ES) 2.0 or Open AL 1.1. The graphics devices of your Game will be set up with a default 32-bit color frame buffer, a 24-bit depth buffer, and an 8-bit stencil buffer ready for your use. These are the active graphics hardware buffers, which are rendered into from your rendering code.

For more advanced usage, you can apply alternative frame buffers using the  class. Immediately after the  method, the frame buffer is swapped/presented to the physical display for the user to see. You can invoke the  method to clear the buffers through any of the methods. You can also call  from code, such as from the   method, to callback onto a method that will be called only once and then swapped/presented to the display. This is useful for presenting ad-hoc updates to the screen during initialization for rendering, such as loading screens.

Game sub-system controllers
The  class also manages game sub-system controllers, such as audio, animation and physics controllers, and provides access to them directly using getter methods. These classes act as controlling interfaces for managing and playing audio and animations that are active in the game, as well as updates to dynamics in the physics systems. These controllers are hosted by the  class and react on lifecycle events being handled in the game.

Game time and state
Once the instance of a  class has started, the game starts a running time. You can call the  to determine how long a game has been running. You can also call  to determine the absolute time that has elapsed since the first   call. This includes any paused time too. You can call the  method and the game will be put into the   state. If the user on the platform puts the game into the background, the game time is also paused. If the user puts the game back into the foreground, the game will invoke  and the game will resume. At any time in the game you can determine the game state by calling. The game state can be,   or.