Class GameApp — Cornell Extensions 2.0a documentation

This is the primary class for creating a game. To implement a game, you subclass this class and override three methods. The three methods are as follows:

start: This method initializes the game state, defining all of the game attributes. This method is like __init__ except that you should not override that method. Overriding __init__ will break your game. Hence we have provided build as an alternative.

update: This method updates the game state at the start of every animation frame. Any code that moves objects or processes user input (keyboard or mouse) goes in this method.

draw: This method draws all of the objects to the screen. The only thing you should have in this method are calls to self.view.draw().

Constructor¶

GameApp(**keywords)¶Creates, but does not start, a new game.

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:

GameApp(width=400,height=400)The game window will not show until you start the game. To start the game, use the method run().

You will never call the constructor or run yourself. That is handled for you in the provided code.

Parameter: keywords (keys are attribute names) – dictionary of keyword arguments

GameApp(**keywords)¶Creates, but does not start, a new game.

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:

GameApp(width=400,height=400)The game window will not show until you start the game. To start the game, use the method run().

You will never call the constructor or run yourself. That is handled for you in the provided code.

Parameter: keywords (keys are attribute names) – dictionary of keyword arguments

Immutable Attributes¶

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

view¶The game view.

Use the draw method in this attribute to display any GObject instance on the screen. See the class GView for more information.

Invariant: Must be instance of GView.

width¶The window width

Invariant: Must be an int or float > 0.

height¶The window height

Invariant: Must be an int or float > 0.

fps¶The number of frames-per-second to animate

By default this value is 60 FPS. However, we cannot guarantee that the FPS is achievable. If you are having performance stuttering, you might want to drop this value to 30 FPS instead.

Invariant: Must be an int or float > 0.

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

view¶The game view.

Use the draw method in this attribute to display any GObject instance on the screen. See the class GView for more information.

Invariant: Must be instance of GView.

width¶The window width

Invariant: Must be an int or float > 0.

height¶The window height

Invariant: Must be an int or float > 0.

fps¶The number of frames-per-second to animate

By default this value is 60 FPS. However, we cannot guarantee that the FPS is achievable. If you are having performance stuttering, you might want to drop this value to 30 FPS instead.

Invariant: Must be an int or float > 0.

Methods¶

Methods to Override¶

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

start()¶Initializes the game state, creating a new game.

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

Never override the built-in method __init__

update(dt)¶Updates the state of the game one animation frame.

This method is called 60x a second (depending on the fps) to provide on-screen animation. Any code that moves objects or processes user input (keyboard or mouse) goes in this method.

Think of this method as the body of the loop. You will need to add attributes that represent the current animation state, so that they can persist across animation frames. These attributes should be initialized in start.

Parameter: dt (int or float) – time in seconds since last update

draw()¶Draws the game objects on the screen.

Every single object that you draw will need to be an attribute of the GameAppclass. This method should largely be a sequence of calls to self.view.draw().

Methods to Inherit¶

You should never override these methods.

run()¶Displays the game window and starts the game.

This is a Kivy reserved method. It is part of the Kivy application process. It should never be overridden.

stop()¶Closes the game window and exit Python.

This is a Kivy reserved method. It is part of the Kivy application process. It should never be overridden.

Return to top level

Methods to Override¶

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

start()¶Initializes the game state, creating a new game.

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

Never override the built-in method __init__

update(dt)¶Updates the state of the game one animation frame.

This method is called 60x a second (depending on the fps) to provide on-screen animation. Any code that moves objects or processes user input (keyboard or mouse) goes in this method.

Think of this method as the body of the loop. You will need to add attributes that represent the current animation state, so that they can persist across animation frames. These attributes should be initialized in start.

Parameter: dt (int or float) – time in seconds since last update

draw()¶Draws the game objects on the screen.

Every single object that you draw will need to be an attribute of the GameAppclass. This method should largely be a sequence of calls to self.view.draw().

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

start()¶Initializes the game state, creating a new game.

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

Never override the built-in method __init__

update(dt)¶Updates the state of the game one animation frame.

This method is called 60x a second (depending on the fps) to provide on-screen animation. Any code that moves objects or processes user input (keyboard or mouse) goes in this method.

Think of this method as the body of the loop. You will need to add attributes that represent the current animation state, so that they can persist across animation frames. These attributes should be initialized in start.

Parameter: dt (int or float) – time in seconds since last update

draw()¶Draws the game objects on the screen.

Every single object that you draw will need to be an attribute of the GameAppclass. This method should largely be a sequence of calls to self.view.draw().

Methods to Inherit¶

You should never override these methods.

run()¶Displays the game window and starts the game.

This is a Kivy reserved method. It is part of the Kivy application process. It should never be overridden.

stop()¶Closes the game window and exit Python.

This is a Kivy reserved method. It is part of the Kivy application process. It should never be overridden.

Return to top level

You should never override these methods.

run()¶Displays the game window and starts the game.

This is a Kivy reserved method. It is part of the Kivy application process. It should never be overridden.

stop()¶Closes the game window and exit Python.

This is a Kivy reserved method. It is part of the Kivy application process. It should never be overridden.

Return to top level

  • Class GameApp

  • Constructor

  • Immutable Attributes

  • Methods

  • Methods to Override

  • Methods to Inherit

  • Documentation overview

  • Game2d Package

  • Previous: Game2d Package

  • Next: Class GInput

  • Documentation overview

  • Game2d Package

  • Previous: Game2d Package

  • Next: Class GInput

This Page

  • Show Source

  • Show Source

This site only collects related articles. Viewing the original, please copy and open the following link:Class GameApp — Cornell Extensions 2.0a documentation

🔥 🎻 Buckshot Roulette Online Real Money Game 🎧
🎮 Latest Articles 🎀 🎻 Popular Articles 🎳
😚 Recommended Articles 🎢
# Article Title Keyword Article Link Article Details
WPT Global