Class GameApp


Primary controller class for a simple game application.

Constructor: creates, but does not start, a new game.

param keywords:dictionary of keyword arguments

Precondition: See below.

To use the constructor for this class, you should provide it with a list of keyword arguments that initialize various attributes. The primary user defined attributes are the window width and height. For example, to create a game that fits inside of a 400x400 window, the constructor


The game window will not show until you start the game. To start the game, use the method run().

Immutable Attributes

These attributes may be read (e.g. used in an expression), but not altered.


The application view.

Pass this attribute to the draw method of a GObject instance to draw it.

Invariant**: Immutable instance of GView.


The window width

Invariant: Immutable float.


The window height

Invariant: Immutable float.


Target animation FPS

We cannot guarantee that the FPS is achievable. Python is not super fast. We do try for 60 FPS, however.

Invariant: Immutable float > 0.


Methods to Override

You will need to replace all of these methods in your subclass.


Initialize the game state.

This method is distinct from the built-in initializer __init__. This method is called once the game is running. You should use it to initialize any game specific attributes.


Called every animation frame.

param dt:time in seconds since last update

Precondition: a number (int or float)

This method is called 60x a second to provide on-screen animation. Think of it as the body of the loop. It is best to have fields that represent the current animation state so that you know where you are in the animation.


Methods to Inherit

You should never override these methods.


Display the game window and start the game


Close the game window and exit Python.

You should never need to call this

Table Of Contents

Previous topic

Class GView

Next topic

Class Sound

This Page