Full API Documentation#

Rubato is a modern 2D game engine for python. Accurate fixed-step physics simulations, robust scene and game object management, event listener system and more all come prepackaged.

Fundamentally, Rubato is built developer-focused. From intricate rigidbody simulations to 2D games, Rubato streamlines development for beginners and the poweruser. And all that finally with some legible documentation.

init(options={})[source]#

Initializes rubato.

Parameters:

options (dict) – A game config. Defaults to the Game defaults.

begin()[source]#

Starts the main game loop.

Raises:

RuntimeError – Rubato has not been initialized before calling.

Game#

The main game module. It controls everything in the game.

class GameProperties[source]#

Bases: type

Defines static property methods for Game.

Warning

This is only a metaclass for the class below it, so you wont be able to access this class. To use the property methods here, simply access them as you would any other Game property.

property state: int#

The state of the game.

The game states are:

Game.RUNNING
Game.STOPPED
Game.PAUSED
Return type:

int

property camera: Camera#

A shortcut getter allowing easy access to the current camera. This is a get-only property.

Note

Returns a pointer to the current camera object. This is so you can access/change the current camera properties faster, but you’d still need to use Game.scenes.current.camera to access the camera directly.

Returns:

The current scene’s camera

Return type:

Camera

class Game[source]#

Bases: object

The main game class.

name#

The title of the game window.

Type:

str

scenes#

The global scene manager.

Type:

SceneManager

background_color#

The background color of the window.

Type:

Color

border_color#

The color of the borders of the window.

Type:

Color

debug#

Turn on debug rendering for everything in the game.

Type:

bool

classmethod constant_loop()[source]#

The constant game loop. Should only be called by rubato.begin().

classmethod update()[source]#

The update loop for the game. Called automatically every frame. Handles the game states. Will always process timed calls.

Scenes and Their Management#

Scenes hold a collection of Game Objects and Groups. It also manages a Camera. Scenes are used to compartmentalize code. For example, you could have each level of your game on a different scene. Then to switch levels you would switch scenes. Every game has a Scene Manager which helps you switch between scenes easily.

Groups also hold a collection of Game Objects and other Groups. Their main purpose is to further compartmentalize items. For example, items in 2 different groups won’t collide with each other. In this tutorial, we won’t be using Groups as we don’t need this functionality here.

SceneManager#

The Scene Manager houses a collection of scenes and allows switching between scenes. It also handles drawing and updating the current scene.

class SceneManager[source]#

Bases: object

The Scene Manager contains and handle multiple scenes.

scenes#

The collection of scenes in the manager. Accessed by scene id.

Type:

Dict[str, Scene]

_current#

The id of the current scene.

Type:

str

__init__()[source]#

Initializes the scene manager with no scenes and current set to 0.

property current: Scene#

Gets the current scene.

Returns:

The current scene.

Return type:

Scene

is_empty()[source]#

Checks if the scene manager contains no scene.

Returns:

True if the scene is empty. False otherwise.

Return type:

bool

add(scene, scene_id)[source]#

Add a scene to the current scene manager. If the manager is empty the current scene will be updated.

Parameters:
  • scene (Scene) – The scene to add to the manager.

  • scene_id (str) – The id of the scene.

Raises:

IdError – The given scene id is already used.

set(scene_id)[source]#

Changes the current scene.

Parameters:

scene_id (str) – The id of the new scene.

setup()[source]#

Calls the setup function of the current scene.

draw()[source]#

Calls the draw function of the current scene.

update()[source]#

Calls the update function of the current scene.

fixed_update()[source]#

Calls the fixed update function of the current scene.

paused_update()[source]#

Calls the paused update function of the current scene.

Scene#

The Scene class which is a collection of groups. It also houses the current scene camera. Scenes are built with a root group that everything is added to.

class Scene[source]#

Bases: object

A scene is a collection of groups.

root#

The base group of game objects in the scene.

Type:

Group

camera#

The camera of this scene.

Type:

Camera

id#

The id of this scene.

Type:

str

__init__()[source]#

Initializes a scene with an empty collection of game objects, a new camera, and a blank id.

add(*items)[source]#

Adds an item to the root group.

Parameters:

item – The item or list of items to add.

delete(item)[source]#

Removes an item from the root group.

Parameters:

item (Union[GameObject, Group]) – The item to remove.

setup()[source]#

The start loop for this scene. It is run before the first frame. Is empty be default and can be overriden.

draw()[source]#

The draw loop for this scene. It is run once every frame. Is empty by default an can beoverridden.

update()[source]#

The update loop for this scene. It is run once every frame, before draw(). Is empty by default an can be overridden.

fixed_update()[source]#

The fixed update loop for this scene. It is run (potentially) many times a frame. Is empty by default an can be overridden.

Note

You should define fixed_update only for high priority calculations that need to match the physics fps.

paused_update()[source]#

The paused update loop for this scene. It is run once a frame when the game is paused. Is empty by default an can be overridden.

Camera#

The Camera module handles where things are drawn. A camera can zoom, pan, and travel along the z-index. Items only render if their z-index is not more than that of the camera’s.

The current scene’s camera can be accessed through Game.camera.

class Camera[source]#

Bases: object

The camera class.

pos#

The current position of the camera.

Type:

Vector

z_index#

The current z_index of the camera.

Type:

int

__init__(pos=Vector(), zoom=1, z_index=100)[source]#

Initializes a camera.

property zoom: float#

The zoom value of the camera.

Return type:

float

transform(point)[source]#

Transforms resolution space coordinates according to camera attributes.

Parameters:

point (Vector) – The point to transform.

Returns:

The translated coordinates.

Return type:

Vector

scale(dimension)[source]#

Scales a given dimension by the camera zoom.

Parameters:

dimension (Any) – The dimension to scale. Can be a scalar or a Vector.

Returns:

The scaled dimension.

Return type:

Any

Group#

Groups contain game objects or other groups and allow separation between game objects.

class Group[source]#

Bases: object

The group class implementation.

__init__(options={})[source]#

Initializes a group object.

Parameters:

options (dict) – A group object config. Defaults to the Group defaults.

add(*items)[source]#

Adds an item to the group.

Parameters:

items (Union[GameObject, Group]) – The item(s) you wish to add to the group

Raises:
  • Error – The item being added is the group itself. A group cannot be added to itself.

  • ValueError – The group can only hold game objects or other groups.

add_group(g)[source]#

Add a group to the group.

add_game_obj(g)[source]#

Add a game object to the group

add_ui_element(ui)[source]#

Add a ui element to the group.

delete(item)[source]#

Removes an item from the group.

Parameters:

item (Union[GameObject, Group]) – The item to remove from the group.

Raises:

ValueError – The item is not in the group and cannot be deleted.

fixed_update()[source]#

Runs a physics iteration on the group. Called automatically by Rubato when added to a scene.

count()[source]#

Counts all the GameObjects in this group and all groups it contains. :returns: The number of GameObjects in a group :rtype: int

Game Object and Components#

Game Objects are the main item in a game. They hold Components, have a position, and have a z-index. By themselves, they have very little functionality.

Components are how Game Objects get their functionality. Each component adds or changes something about the Game Object. For example, an Image component draws an image from your filesystem to the game at the Game Object’s position.

Game Object#

A game object is a basic element that holds components, postion, and z_index.

class GameObject[source]#

Bases: object

The base game object class.

name#

The name of the game object. Will default to: “Game Object {number in group}”

Type:

str

pos#

The current position of the game object.

Type:

Vector

z_index#

The z_index of the game object.

Type:

int

components#

All the components attached to this game object.

Type:

List[Component]

__init__(options={})[source]#

Initializes a game object.

Parameters:

options (dict) – A game object config. Defaults to the Game Object defaults.

property relative_pos: Vector#

The relative position of the game object.

Return type:

Vector

add(component)[source]#

Add a component to the game object.

Parameters:

component (Component) – The component to add.

Raises:

DuplicateComponentError – Raised when there is already a component of the same type on the game object.

Returns:

The current game object

Return type:

GameObject

remove(comp_type)[source]#

Removes a component from the game object.

Parameters:

comp_type (type) – The type of the component to remove.

Raises:

Warning – The component was not in the game object and nothing was removed.

remove_all(comp_type)[source]#

Removes all components of a type from the game object.

Parameters:

comp_type (type) – The type of the component to remove.

Raises:

Warning – The components were not in the game object and nothing was removed.

get(comp_type)[source]#

Gets a component from the game object.

Parameters:

comp_type (type) – The type of the component to search for.

Returns:

The component if it was found or None if it wasn’t.

Return type:

Union[Component, None]

get_all(comp_type)[source]#

Gets all the components of a type from the game object.

Parameters:

comp_type (type) – The type of component to search for.

Returns:

A list containing all the components of that type. If no components were found, the

list is empty.

Return type:

List[Component]

delete()[source]#

Deletes and frees everything from the game object. This is called when you remove it from a group or scene.

Warning

Calling this will render the gameobject useless in the future.

static map_coord(coord)[source]#

Maps a coordinate to the camera’s coordinate system.

Parameters:

coord (Vector) – The coordinate to map.

Returns:

The mapped coordinate.

Return type:

Vector

static scale_value(value)[source]#

Scales a value to match the current camera’s scale.

Parameters:

value (Union[int, float]) – The value to scale.

Returns:

The scaled value.

Return type:

Union[int, float]

UI Element#

A UIElement is a game object that is drawn to the screen at a constant position no matter how the camera moves. They are drawn at the camera’s z-index, meaning they will usually draw on top of other game objects.

class UIElement[source]#

Bases: GameObject

Defines a UIElement.

name#

The name of the UI. Will default to: “UI {number in group}”

Type:

str

pos#

The current position of the UI.

Type:

Vector

components#

All the components attached to this UI.

Type:

List[Component]

__init__(options={})[source]#

Initializes a UIElement.

Parameters:

options (dict) – A UIElement config. Defaults to the UI Element defaults.

property z_index#

The z_index of the UIElement.

property relative_pos: Vector#

The relative position of the UIElement.

Return type:

Vector

static map_coord(coord)[source]#

Maps a coordinate to the UIElement’s coordinate system.

Parameters:

coord (Vector) – The coordinate to map.

Returns:

The mapped coordinate.

Return type:

Vector

static scale_value(value)[source]#

Scales a value to match the UIElement’s scale.

Parameters:

value (Union[int, float]) – The value to scale.

Returns:

The scaled value.

Return type:

Union[int, float]

Components#

The default Component class.

The component module that represents the template for all components.

Attention

Each component can only be attached to one game object. To add one component to multiple game objects, use the clone() method.

class Component[source]#

Bases: object

A component adds functionality to the game object it is attached to.

gameobj#

The game object this component is attached to.

Type:

GameObject

singular#

Whether multiple components of the same type are allowed on a game object.

Type:

bool

offset#

The offset from the center of the game object that the hitbox should be placed.

Type:

Vector

__init__()[source]#

Initializes a Component. This is a superclass and as such does not take parameters.

draw()[source]#

The draw function template for a component subclass.

Return type:

None

update()[source]#

The update function template for a component subclass.

Return type:

None

setup()[source]#

The setup function template for a component subclass.

Return type:

None

fixed_update()[source]#

The physics function template for a component subclass.

delete()[source]#

The delete function template for a component subclass.

clone()[source]#

Clones the component.

Return type:

Component

Image#

The image component that renders an image from the filesystem.

class Image[source]#

Bases: Component

A component that handles Images.

aa#

Whether or not to enable anti aliasing.

Type:

bool

flipx#

Whether or not to flip the image along the x axis

Type:

bool

flipy#

Whether or not to flip the image along the y axis

Type:

bool

visible#

Whether or not the image is visible.

Type:

bool

__init__(options={})[source]#

Initializes an Image.

Parameters:

options (dict) – A Image config. Defaults to the Image defaults.

property image: sdl2.SDL_Surface#

The SDL Surface of the image.

Return type:

SDL_Surface

property rotation: float#

The rotation of the image.

Return type:

float

property scale: Vector#

The scale of the image in relation to it’s original size.

Return type:

Vector

get_size()[source]#

Gets the current size of the image.

Returns:

The size of the image

Return type:

Vector

get_size_original()[source]#

Gets the original size of the image.

Returns:

The original size of the image.

Return type:

Vector

resize(new_size)[source]#

Resize the image to a given size in pixels.

Parameters:

new_size (Vector) – The new size of the image in pixels.

draw_point(pos, color=Color.black)[source]#

Draws a point on the image.

Parameters:
  • pos (Vector) – The position to draw the point.

  • color (Color) – The color of the point. Defaults to black.

draw_line(start, end, color=Color.black, width=1)[source]#

Draws a line on the image.

Parameters:
  • start (Vector) – The start of the line.

  • end (Vector) – The end of the line.

  • color (Color) – The color of the line. Defaults to black.

  • width (int) – The width of the line. Defaults to 1.

cam_update()[source]#

Updates the image sizing when the camera zoom changes.

draw()[source]#

The draw function template for a component subclass.

delete()[source]#

Deletes the image component

clone()[source]#

Clones the current image.

Returns:

The cloned image.

Return type:

Image

Text#

A text component.

class Text[source]#

Bases: Component

A text component subclass. Add this to game objects or UI elements to give them text.

__init__(options={})[source]#

Initializes a Label.

Parameters:

options (dict) – A Text config. Defaults to the Text defaults.

property text: str#

The text of the Text.

Return type:

str

property justify: str#

The justification of the text.

Return type:

str

property align: str#

The alignment vector of the text.

Return type:

str

property width: int#

The maximum width of the text. Will automatically wrap the text.

Return type:

int

property font_size: int#

The font size.

Warning

Don’t set this too high or font smoothing may misbehave on some systems.

Return type:

int

property font_color: Color#

The font color.

Return type:

Color

add_style(style)[source]#

Add a style to the font (bold, italic, underline, strikethrough, normal).

remove_style(style)[source]#

Remove a style from a font.

generate_surface()[source]#

(Re)generates the surface of the text.

draw()[source]#

The draw function template for a component subclass.

delete()[source]#

Deletes the text component.

clone()[source]#

Clones the text component.

Return type:

Text

Animation#

This is the animation component module for game objects.

class Animation[source]#

Bases: Component

Animations are a series of images that update automatically in accordance with parameters.

rotation#

The rotation of the animation.

Type:

float

default_state#

The key of the default state. Defaults to None.

Type:

Union[str, None]

current_state#

The key of the current state. Defaults to “”.

Type:

str

animation_frames_left#

The number of animation frames left.

Type:

int

loop#

Whether the animation should loop. Defaults to False.

Type:

bool

aa#

Whether or not to enable anti aliasing.

Type:

bool

flipx#

Whether or not to flip the animation along the x axis.

Type:

bool

flipy#

Whether or not to flip the animation along the y axis.

Type:

bool

visible#

Whether or not the animation is visible.

Type:

bool

__init__(options={})[source]#

Initializes an Animation.

Parameters:

options (dict) – A Animation config. Defaults to the Animation defaults.

property fps#

The fps of the animation.

property current_frame: int#

The current frame that the animation is on.

Return type:

int

property image: sdl2.surface.SDL_Surface#

The current SDL Surface holding the image.

Return type:

SDL_Surface

property anim_frame: Image#

The current animation frame.

Return type:

Image

set_current_state(new_state, loop=False, freeze=-1)[source]#

Set the current animation state.

Parameters:
  • new_state (str) – The key of the new current state.

  • loop (bool) – Whether to loop the state. Defaults to False.

  • freeze (int) – Freezes the animation once the specified frame is reached (No animation). Use -1 to never freeze. Defaults to -1.

Raises:

KeyError – The new_state key is not in the initialized states.

resize(new_size)[source]#

Resize the Animation to a given size in pixels.

Parameters:

new_size (Vector) – The new size of the Animation in pixels.

reset()[source]#

Reset the animation state back to the first frame.

add(state_name, images)[source]#

Adds a state to the animation.

Parameters:
  • state_name (str) – The key used to reference this state.

  • images (List[Image]) – A list of images to use as the animation.

add_folder(state_name, rel_path)[source]#

Adds a state from a folder of images. Directory must be solely comprised of images.

Parameters:
  • state_name (str) – The key used to reference this state.

  • rel_path (str) – The relative path to the folder you wish to import

add_spritesheet(state_name, spritesheet, from_coord=Vector(), to_coord=Vector())[source]#

Adds a state from a spritesheet. Will include all sprites from the from_coord to the to_coord.

Parameters:
  • state_name (str) – The key used to reference this state.

  • spritesheet (Spritesheet) – The spritesheet to use.

  • from_coord (Vector) – The grid coordinate of the first frame. Defaults to Vector().

  • to_coord (Vector) – The grid coordinate of the last coord. Defaults to Vector().

Example

animation.add_spritesheet("idle", spritesheet, Vector(0, 0), Vector(1, 3))
# This will add the frames (0, 0) to (0, size) and (1, 0) to (1, 3) inclusive to the animation
# with the state name "idle".

animation.add_spritesheet("idle", spritesheet, to_coord=spritesheet.end)
# This will just load from the start to the end of the spritesheet.
setup()[source]#

Sets up the animation component.

draw()[source]#

Draws the animation frame and steps the animation forward.

anim_tick()[source]#

An animation processing tick.

delete()[source]#

Deletes the animation component

clone()[source]#

Clones the animation.

Return type:

Animation

Spritesheet#

A module to load, manage, and interact with spritesheets.

class Spritesheet[source]#

Bases: object

A spritesheet from the filesystem.

__init__(options={})[source]#

Initializes a Spritesheet.

Parameters:

options (dict) – A Spritesheet config. Defaults to the Spritesheet defaults.

Raises:

IndexError – If user does not load the entire sheet.

property grid_size: Vector#

The size of the spritesheet grid (readonly).

Return type:

Vector

property sprite_size: Vector#

The size of each sprite (readonly).

Return type:

Vector

property sheet: Image#

The actual spritesheet image (readonly).

Return type:

Image

property sprites: List[List[Image]]#

The list of all the sprites as images (readonly).

Return type:

List[List[Image]]

property end#

The end indexes of the Spritesheet as a vector.

Example

You can use spritesheet.get(*spritesheet.end) to get the final image

get(x, y)[source]#

Gets the Image at the coorsponding grid coordinate of the spritesheet.

Parameters:
  • x (int) – The x grid coordinate.

  • y (int) – The y grid coordinate.

Raises:

IndexError – One or both of the coordinates are out of range of the spritesheet’s size.

Returns:

The image of the cooresponding sprite.

Return type:

Image

static from_folder(rel_path, sprite_size, default_state=None)[source]#

Creates an Animation from a folder of spritesheets. Directory must be comprised solely of spritesheets. Added alphabetically. Default is the first sheet loaded.

Parameters:
  • rel_path (str) – The relative path to the folder you wish to import

  • sprite_size (Vector) – The size of a single sprite in your spritesheet, should be the same in all imported sheets.

  • default_state – Sets the default state of the animation.

Returns:

the animation loaded from the folder of spritesheets

Return type:

Animation

Hitbox#

Various hitbox components that enable collisions

class Hitbox[source]#

Bases: Component

A hitbox superclass. Do not use this to attach hitboxes to your game objects. Instead, use Polygon, Rectangle, or Circle.

debug#

Whether to draw a green outline around the Polygon or not.

Type:

bool

trigger#

Whether this hitbox is just a trigger or not.

Type:

bool

scale#

The scale of the polygon

Type:

int

on_collide#

The on_collide function to call when a collision happens with this hitbox.

Type:

Callable

color#
Type:

Color

tag#

The tag of the hitbox (can be used to identify hitboxes)

Type:

str

__init__(options={})[source]#

Initializes a Hitbox.

Parameters:

options (dict) – A Hitbox config. Defaults to the Hitbox defaults.

property pos: Vector#

The getter method for the position of the hitbox’s center

Return type:

Vector

update()[source]#

The update function template for a component subclass.

bounding_box_dimensions()[source]#

Returns the dimensions of the bounding box surrounding the polygon.

Returns:

A vector with the x variable holding the width and the y variable holding the height.

Return type:

Vector

overlap(other)[source]#

Wraps the SAT collide function. Returns a ColInfo manifold if a collision occurs but does not resolve.

Return type:

Optional[ColInfo]

collide(other)[source]#

Collides two hitboxes and resolves the collision using RigidBody impulse momentum if applicable.

Parameters:
  • other (Hitbox) – The other rigidbody to collide with.

  • on_collide – The function to run when a collision is detected. Defaults to None.

Returns:

Returns a collision info object if a collision is detected or nothing if no collision is detected.

Return type:

Union[ColInfo, None]

class Polygon[source]#

Bases: Hitbox

A polygon Hitbox subclass with an arbitrary number of vertices.

verts#

A list of the vertices in the Polygon, in either clockwise or anticlockwise direction.

Type:

List[Vector]

scale#

The scale of the polygon.

Type:

Union[float, int]

__init__(options={})[source]#

Initializes a Polygon.

Parameters:

options (dict) – A Polygon config. Defaults to the Polygon defaults.

clone()[source]#

Clones the Polygon

Return type:

Polygon

transformed_verts()[source]#

Maps each vertex with the Polygon’s scale and rotation

Return type:

List[Vector]

real_verts()[source]#

Returns the a list of vertices in absolute coordinates

Return type:

List[Vector]

bounding_box_dimensions()[source]#

Returns the width and height of the smallest x, y axis aligned bounding box that fits around the polygon.

Returns:

The vector representation of the width and height.

Return type:

Vector

draw()[source]#

The draw function template for a component subclass.

static generate_polygon(num_sides, radius=1)[source]#

Creates a normal polygon with a specified number of sides and an optional radius.

Parameters:
  • num_sides (int) – The number of sides of the polygon.

  • radius (Union[float, int]) – The radius of the polygon. Defaults to 1.

Raises:

SideError – Raised when the number of sides is less than 3.

Returns:

The vertices of the polygon.

Return type:

List[Vector]

class Rectangle[source]#

Bases: Hitbox

A rectangle implementation of the Hitbox subclass.

width#

The width of the rectangle

Type:

int

height#

The height of the rectangle

Type:

int

rotation#

The rotation of the rectangle

Type:

float

__init__(options)[source]#

Initializes a Rectangle.

Parameters:

options (dict) – A Rectangle config. Defaults to the Rectangle defaults.

property top_left#

The top left corner of the rectangle.

Note

This can only be accessed and set after the Rectangle has been added to a Game Object.

property bottom_left#

The bottom left corner of the rectangle.

Note

This can only be accessed and set after the Rectangle has been added to a Game Object.

property top_right#

The top right corner of the rectangle.

Note

This can only be accessed and set after the Rectangle has been added to a Game Object.

property bottom_right#

The bottom right corner of the rectangle.

Note

This can only be accessed and set after the Rectangle has been added to a Game Object.

property bottom#

The bottom side of the rectangle.

Note

This can only be accessed and set after the Rectangle has been added to a Game Object.

vertices()[source]#

Generates a list of the rectangle’s vertices with no transformations applied.

Returns:

The list of vertices

Return type:

List[Vector]

transformed_verts()[source]#

Generates a list of the rectangle’s vertices, scaled and rotated.

Returns:

The list of vertices

Return type:

List[Vector]

real_verts()[source]#

Generates a list of the rectangle’s vertices, relative to its position.

Returns:

The list of vertices

Return type:

List[Vector]

draw()[source]#

The draw function template for a component subclass.

clone()[source]#

Clones the component.

Return type:

Rectangle

class Circle[source]#

Bases: Hitbox

A circle Hitbox subclass defined by a position, radius, and scale.

radius#

The radius of the circle.

Type:

int

scale#

The scale of the circle.

Type:

int

__init__(options={})[source]#

Initializes a Circle.

Parameters:

options (dict) – A Circle config. Defaults to the Circle defaults.

transformed_radius()[source]#

Gets the true radius of the circle

Return type:

int

draw()[source]#

The draw function template for a component subclass.

clone()[source]#

Clones the component.

Return type:

Circle

class ColInfo[source]#

Bases: object

A class that represents information returned in a successful collision

shape_a#

A reference to the first shape.

Type:

Union[Circle, Polygon, None]

shape_b#

A reference to the second shape.

Type:

Union[Circle, Polygon, None]

seperation#

The vector that would separate the two colliders.

Type:

Vector

__init__(shape_a, shape_b, sep=Vector())[source]#

Initializes a Collision Info manifold. This is used internally by SAT.

flip()[source]#

Flips the reference shape in a collision manifold

Returns:

a reference to self.

Return type:

ColInfo

class SAT[source]#

Bases: object

A general class that does the collision detection math between different hitboxes.

static overlap(shape_a, shape_b)[source]#

Checks for overlap between any two shapes (Polygon or Circle)

Parameters:
  • shape_a (Hitbox) – The first shape.

  • shape_b (Hitbox) – The second shape.

Returns:

If a collision occurs, a ColInfo is returned. Otherwise None is returned.

Return type:

Union[ColInfo, None]

static circle_circle_test(circle_a, circle_b)[source]#

Checks for overlap between two circles

Return type:

Optional[ColInfo]

static circle_polygon_test(circle, polygon)[source]#

Checks for overlap between a circle and a polygon

Return type:

Optional[ColInfo]

static polygon_polygon_test(shape_a, shape_b)[source]#

Checks for overlap between two polygons

Return type:

Optional[ColInfo]

static poly_poly_helper(poly_a, poly_b)[source]#

Checks for half overlap. Don’t use this by itself unless you know what you are doing.

Return type:

Optional[ColInfo]

static perpendicular_axis(verts, index)[source]#

Finds a vector perpendicular to a side

Return type:

Vector

static project_verts(verts, axis)[source]#

Projects the vertices onto a given axis. Returns as a vector x is min, y is max

Return type:

Vector

RigidBody#

The Rigidbody component contains an implementation of rigidbody physics. They have hitboxes and can collide and interact with other rigidbodies.

class RigidBody[source]#

Bases: Component

A RigidBody implementation with built in physics and collisions. Rigidbodies require hitboxes.

static#

Whether or not the rigidbody is static (as in, it does not move).

Type:

bool

gravity#

The acceleration of the gravity that should be applied.

Type:

Vector

friction#

The friction coefficient of the Rigidbody (usually a a value between 0 and 1).

Type:

float

max_speed#

The maximum speed of the Rigidbody.

Type:

Vector

min_speed#

The minimum speed of the Rigidbody.

Type:

Vector

velocity#

The current velocity of the Rigidbody.

Type:

Vector

inv_mass#

The inverse of the mass of the Rigidbody (0 if the mass is infinite).

Type:

float

bounciness#

How bouncy the rigidbody is (usually a value between 0 and 1).

Type:

float

__init__(options={})[source]#

Initializes a Rigidbody.

Parameters:

options (dict) – A rigidbody config. Defaults to the Rigidbody defaults.

property mass: float#

The mass of the Rigidbody (readonly)

Return type:

float

physics()[source]#

Applies general kinematic laws to the rigidbody.

add_force(force)[source]#

Add a force to the Rigidbody.

Parameters:

force (Vector) – The force to add.

add_cont_force(impulse, time)[source]#

Add a continuous force to the Rigidbody. A continuous force is a force that is continuously applied over a time period. (the force is added every frame for a specific duration).

Parameters:
  • impulse (Vector) – The force to add.

  • time (int) – The time in seconds that the force should be added.

fixed_update()[source]#

The physics loop for the rigidbody component.

clone()[source]#

Clones the component.

Return type:

RigidBody

static handle_collision(col)[source]#

Resolve the collision between two rigidbodies. Utilizes a simplistic impulse resolution method.

Parameters:

col (ColInfo) – The collision information.

Hardware Interaction#

All of these static classes let you interact with the hardware. Either by checking for user input, drawing to the screen or playing a sound.

Display#

Global display class that allows for easy screen and window management.

class DisplayProperties[source]#

Bases: type

Defines static property methods for Display.

Attention

This is only a metaclass for the class below it, so you wont be able to access this class. To use the property methods here, simply access them as you would any other Display property.

property window_size: Vector#

The pixel size of the physical window.

Warning

Using this value to determine the placement of your game objects will lead to unexpected results. Instead you should use Display.res

Return type:

Vector

property res: Vector#

The pixel resolution of the game. This is the number of virtual pixels on the window.

Example

The window (Display.window_size) could be rendered at 720p while the resolution is still at 1080p. This means that you can place game objects at 1000, 1000 and still have them draw despite the window not being 1000 pixels tall.

Warning

While this value can be changed, it is recommended that you do not change it as it will scale your entire project in ways you might not expect.

Return type:

Vector

property window_pos: Vector#

The current position of the window in terms of screen pixels

Return type:

Vector

property display_ratio: Vector#

The ratio of the renderer resolution to the window size. This is a read-only property.

Returns:

The ratio of the renderer resolution to the window size seperated by x and y.

Return type:

Vector

class Display[source]#

Bases: object

A static class that houses all of the display information

window#

The pysdl2 window element.

Type:

sdl2.Window

renderer#

The pysdl2 renderer element.

Type:

sdl2.Renderer

format#

The pysdl2 pixel format element.

Type:

sdl2.PixelFormat

classmethod set_window_icon(path)[source]#

Set the icon of the window.

Warning

The image must be less than 128x128

Parameters:

path (str) – The path to the icon.

classmethod draw_point(pos, color)[source]#

Draw a point onto the renderer.

Parameters:
  • pos (Vector) – The position of the point.

  • color (Color) – The color to use for the pixel. Defaults to black.

classmethod draw_line(p1, p2, color, width=1)[source]#

Draw a line onto the renderer.

Parameters:
  • p1 (Vector) – The first point of the line.

  • p2 (Vector) – The second point of the line.

  • color (Color) – The color to use for the line. Defaults to black.

  • width (int) – The width of the line. Defaults to 1.

classmethod draw_text(text, font, pos=Vector(), justify=Defaults.text_defaults['justify'], align=Defaults.text_defaults['align'], width=Defaults.text_defaults['width'])[source]#

Draws some text onto the renderer.

Parameters:
  • text (str) – The text to draw.

  • font (Font) – The Font object to use.

  • pos (Vector) – The position of the text. Defaults to Vector(0, 0).

  • justify (str) – The justification of the text. (left, center, right). Defaults to “left”.

  • align (Vector) – The alignment of the text. Defaults to Vector(0, 0).

  • width (int) – The maximum width of the text. Will automatically wrap the text. Defaults to -1.

classmethod update(tx, pos)[source]#

Update the current screen.

Parameters:
  • tx (Texture) – The texture to draw on the screen.

  • pos (Vector) – The position to draw the texture on.

classmethod clone_surface(surface)[source]#

Clones an SDL surface.

Parameters:

surface (SDL_Surface) – The surface to clone.

Returns:

The cloned surface.

Return type:

sdl2.SDL_Surface

class property top_left: Vector#

The position of the top left of the window.

Return type:

Vector

class property top_right: Vector#

The position of the top right of the window.

Return type:

Vector

class property bottom_left: Vector#

The position of the bottom left of the window.

Return type:

Vector

class property bottom_right: Vector#

The position of the bottom right of the window.

Return type:

Vector

class property top_center: Vector#

The position of the top center of the window.

Return type:

Vector

class property bottom_center: Vector#

The position of the bottom center of the window.

Return type:

Vector

class property center_left: Vector#

The position of the center left of the window.

Return type:

Vector

class property center_right: Vector#

The position of the center right of the window.

Return type:

Vector

class property center: Vector#

The position of the center of the window.

Return type:

Vector

class property top: int#

The position of the top of the window.

Return type:

int

class property right: int#

The position of the right of the window.

Return type:

int

class property left: int#

The position of the left of the window.

Return type:

int

class property bottom: int#

The position of the bottom of the window.

Return type:

int

Input#

The Input module is the way you collect input from the user.

class Input[source]#

Bases: object

The input class, handling keyboard and mouse getter and setter functionality

Go here for a list of all the available keys.

classmethod key_pressed(*keys)[source]#

Checks if keys are pressed.

Parameters:

*keys – The names of the keys to check.

Returns:

Whether or not the keys are pressed.

Return type:

bool

Example

if rb.Input.key_pressed("a"):
    # handle the "a" keypress

if rb.Input.key_pressed("shift", "w"):
    # handle the "shift+w" keypress
classmethod get_keyboard_state()[source]#

Returns a list with the current SDL keyboard state.

classmethod get_name(code)[source]#

Gets the name of a key from its keycode.

Parameters:

code (int) – A keycode.

Returns:

The corresponding key.

Return type:

str

classmethod mods_from_code(code)[source]#

Gets the modifier names from a mod code.

Parameters:

code (int) – The mod code.

Returns:

A list with the names of the currently pressed modifiers.

Return type:

List[str]

classmethod key_from_name(char)[source]#

Gets the keycode of a key from its name.

Parameters:

char (str) – The name of the key.

Returns:

The corresponding keycode.

Return type:

int

classmethod scancode_from_name(char)[source]#

Gets the scancode of a key from its name.

Parameters:

char (str) – The name of the key.

Returns:

The corresponding scancode.

Return type:

int

classmethod window_focused()[source]#

Checks if the display has keyboard focus.

Returns:

True if the window is focused, false otherwise.

Return type:

bool

classmethod mouse_is_pressed()[source]#

Checks which mouse buttons are pressed.

Returns:

A tuple with 5 booleans representing the state of each mouse button. (button1, button2, button3, button4, button5)

Return type:

Tuple[bool]

static get_mouse_pos()[source]#

The current position of the mouse.

Returns:

A Vector representing position.

Return type:

Vector

classmethod mouse_is_visible()[source]#

Checks if the mouse is currently visible.

Returns:

True for visible, false otherwise.

Return type:

bool

classmethod set_mouse_visibility(toggle)[source]#

Sets the mouse visibility.

Parameters:

toggle (bool) – True to show the mouse and false to hide the mouse.

classmethod mouse_in(center, dims)[source]#

Checks if the mouse is inside a rectangle defined by its center and dimensions

Parameters:
  • center (Vector) – The center of the rectangle.

  • dims (Vector) – The dimensions of the rectangle. Defaults to Vector(1, 1).

Returns:

Whether or not the mouse is in the defined rectangle.

Return type:

bool

Sound#

A fully functional, multi-channel sound system.

class Sound[source]#

Bases: object

A sound class that is used to manage the sounds throughout the project.

loaded_sounds#

A dictionary housing all the loaded sounds, stored by their name.

Type:

Dict[str, Sound]

__init__(rel_path, sound_name=None)[source]#

Initializes a sound.

Parameters:
  • rel_path (str) – The relative path to the sound file you wish to import.

  • sound_name (optional) – The name of the sound. Defaults to the name of the file.

property state: int#

The current state of the sound.

The possible states are:

Sound.STOPPED
Sound.PLAYING
Sound.PAUSED
Returns:

The current state of the sound.

Return type:

int

play(loops=0)[source]#

Plays a sound.

Parameters:
  • sound_name – The name of the sound to play.

  • loops (int) – The number of times to loop a sound after the first play through. Use -1 to loop forever. Defaults to 0.

stop()[source]#

Stops all instances of the sound.

pause()[source]#

Pauses all instances of the sound.

resume()[source]#

Resumes all instance of the sound.

classmethod import_sound_folder(rel_path, duplicate_names=False)[source]#

Imports a folder of sounds, saving each one in the loaded_sounds dictionary by filename.

Parameters:
  • rel_path (str) – The relative path to the folder you wish to import.

  • duplicate_names – if you wish to have duplicate names to your sounds,

  • name (it will use the relative and the sound path for the sounds) –

classmethod get_sound(sound_name)[source]#

Gets the sound based on the sound name.

Parameters:

sound_name (str) – The name of the sound.

Raises:

IdError – No sound is associated to the sound name.

Returns:

The sound.

Return type:

Sound

Utilities#

These classes are utility classes that are used to make certain tasks easier.

Vector#

A vector implementation.

class Vector[source]#

Bases: object

A Vector object that defines a 2D point in space

x#

The x coordinate.

Type:

Union[float, int]

y#

The y coordinate.

Type:

Union[float, int]

__init__(x=0, y=0)[source]#

Initializes a vector.

Parameters:
  • x (Union[float, int]) – The x coordinate. Defaults to 0.

  • y (Union[float, int]) – The y coordinate. Defaults to 0.

property magnitude: float#

The magnitude of the vector.

Return type:

float

property mag_squared: float#

The squared magnitude of the vector.

Return type:

float

property angle: float#

The angle of the vector

Return type:

float

unit()[source]#

Returns the unit vector of this vector.

Return type:

Vector

translate(x, y)[source]#

Translates the vector’s x y and z coordinates by some constants.

Parameters:
  • x (Union[float, int]) – The change in x.

  • y (Union[float, int]) – The change in y.

to_tuple()[source]#

Returns the x and y coordinates of the vector as a tuple.

Return type:

tuple

dot(other)[source]#

Takes the dot product of vectors.

Parameters:

other (Vector) – The other vector.

Returns:

The resulting dot product.

Return type:

Union[float, int]

cross(other)[source]#

Takes the cross product of vectors.

Parameters:

other (Vector) – The other vector.

Returns:

The resulting cross product.

Return type:

Union[float, int]

clamp(lower, upper, absolute=False)[source]#

Clamps x and y between the two values given.

Parameters:
  • lower (Union[Vector, int, float]) – The lower bound.

  • upper (Union[Vector, int, float]) – The upper bound.

  • absolute (bool) – Whether to clamp the absolute value of the vector instead of the actual value.

transform(scale, rotation)[source]#

Transforms the vector by the scale and rotation, relative to the original vector.

Parameters:
  • scale – The scale by which the vector’s length is multiplied.

  • rotation – The angle by which the vector angle is rotated counterclockwise in degrees.

Returns:

The newly transformed Vector (based on the parent).

Return type:

Vector

to_int()[source]#

Returns a new vector with values that are ints.

Return type:

Vector

tuple_int()[source]#

Returns a tuple with rounded values.

Return type:

tuple

clone()[source]#

Returns a copy of the vector.

Return type:

Vector

lerp(target, t)[source]#

Lerps the current vector to target by a factor of t.

Parameters:
  • target (Vector) – The target Vector.

  • t (float) – The lerping amount (between 0 and 1).

Returns:

The resulting vector.

Return type:

Vector

round(decimal_places=0)[source]#

Rounds x and y to a number of decimal places.

Parameters:

decimal_places (int) – The amount of decimal places rounded to.

ceil()[source]#

Ceil the X and Y values of the Vector.

Returns:

The “Ceil”ed Vector.

Return type:

Vector

floor()[source]#

Floors the X and Y values of the Vector

Returns:

The “Floor”ed Vector

Return type:

Vector

abs()[source]#

Absolute value of the Vector.

Returns:

The absolute valued Vector

Return type:

Vector

dir_to(other)[source]#

Direction from the Vector to another Vector.

Parameters:

other (Vector) – the position to which you are pointing

Return type:

Vector

Returns:

A unit vector that is in the direction to the position passed in

static from_radial(magnitude, angle)[source]#

Gives you a Vector from the given direction and distance.

Parameters:
  • magnitude (float) – Length of vector.

  • angle (float) – Direction of vector in radians.

Returns:

Vector from the given direction and distance

Return type:

Vector

static is_vectorlike(subscriptable)[source]#

Checks whether a subscriptable object is vector_like ie. length 2, handles error message.

Parameters:

subscriptable (Union[Vector, List[UnionType[int, float]], Tuple[UnionType[int, float]]]) – An object to check whether it is length 2 and subscriptable.

Returns:

True if length 2, False if not, and raises an error if wrong type.

Return type:

bool

Example

>>> Vector.is_vectorlike((0, 0))
True
>>> Vector.is_vectorlike((0, 0, 0))
False
class property zero[source]#

A zeroed Vector

class property one[source]#

A Vector with all ones

class property up[source]#

A Vector in the up direction

class property left[source]#

A Vector in the left direction

class property down[source]#

A Vector in the down direction

class property right[source]#

A Vector in the right direction

class property infinity[source]#

A Vector at positive infinity

Math#

The math module includes some helper functions for commonly used equations.

class Math[source]#

Bases: object

A more complete math class.

INF#

The max value of a float.

Type:

float

classmethod clamp(a, lower, upper)[source]#

Clamps a value.

Parameters:
  • a (Union[float, int]) – The value to clamp.

  • lower (Union[float, int]) – The lower bound of the clamp.

  • upper (Union[float, int]) – The upper bound of the clamp.

Returns:

The clamped result.

Return type:

float

classmethod sign(n)[source]#

Checks the sign of n.

Parameters:

n (Union[float, int]) – A number to check.

Returns:

The sign of the number. (1 for positive, 0 for 0, -1 for negative)

Return type:

int

classmethod lerp(a, b, t)[source]#

Linearly interpolates between lower and upper bounds by t

Parameters:
  • a (Union[float, int]) – The lower bound.

  • b (Union[float, int]) – The upper bound.

  • t (float) – Distance between upper and lower (1 gives b, 0 gives a).

Returns:

The lerped value.

Return type:

float

Time#

A static time class to monitor time and to call functions in the future.

class TimeProperties[source]#

Bases: type

Defines static property methods for Time.

Warning

This is only a metaclass for the class below it, so you wont be able to access this class. To use the property methods here, simply access them as you would any other Time property.

property smooth_fps: float#

The average fps over the past 5 frames. This is a get-only property.

Return type:

float

property now: int#

The time since the start of the game, in milliseconds. This is a get-only property.

Return type:

int

class Time[source]#

Bases: object

The time class

frames#

The total number of elapsed frames since the start of the game.

Type:

int

fps#

The current fps of this frame.

Type:

float

target_fps#

The fps that the game should try to run at. 0 means that the game’s fps will not be capped. Defaults to 0.

Type:

float

physics_fps#

The fps that the physics should run at. Defaults to 60.

Type:

float

delta_time#

The number of milliseconds since the last frame.

Type:

int

fixed_delta#

The number of milliseconds since the last fixed update.

Type:

int

classmethod delayed_call(time_delta, func)[source]#

Calls the function func at a later time.

Parameters:
  • time_delta (int) – The time from now (in milliseconds) to run the function at.

  • func (Callable) – The function to call.

classmethod delayed_frames(frames_delta, func)[source]#

Calls the function func at a later frame.

Parameters:
  • frames_delta (int) – The number of frames to wait.

  • func (Callable) – The function to call

classmethod milli_to_sec(milli)[source]#

Converts milliseconds to seconds.

Parameters:

milli (int) – A number in milliseconds.

Returns:

The converted number in seconds.

Return type:

float

classmethod sec_to_milli(sec)[source]#

Converts seconds to milliseconds.

Parameters:

sec (int) – A number in seconds.

Returns:

The converted number in milliseconds.

Return type:

float

classmethod process_calls()[source]#

Processes the delayed function call as needed

Color#

This color module contains the Color class, which is used to represent colors in the game.

class Color[source]#

Bases: object

An RGBA color.

r#

The red value.

Type:

int

g#

The green value.

Type:

int

b#

The blue value.

Type:

int

a#

The alpha value.

Type:

int

__init__(r=0, g=0, b=0, a=255)[source]#

Initializes an Color class.

Parameters:
  • r (int) – The red value. Defaults to 0.

  • g (int) – The green value. Defaults to 0.

  • b (int) – The blue value. Defaults to 0.

  • a (int) – The alpha value. Defaults to 255.

property rgba32#

The RGBA32 representation of the color.

darker(amount=20)[source]#

Returns a darker copy of the color. It subtracts amount from the RGB values.

Parameters:

amount (int) – How much darker. Defaults to 20.

Returns:

The resultant color.

Return type:

Color

lighter(amount=20)[source]#

Returns a lighter copy of the color. It adds amount to the RGB values.

Parameters:

amount (int) – How much lighter. Defaults to 20.

Returns:

The resultant color.

Return type:

Color

mix(other, t=0.5, mode='mix')[source]#

Mix two colors together.

Parameters:
  • other (Color) – The other color.

  • t (float) – The interpolation amount (0 to 1). Defaults to 0.5.

  • mode (str) – The blending mode (“linear”, “mix”, “blend”). Linear is the linear interpolation between the two colors. Mix and Blend are 2 different algorithms to mix colors. They tend to look better then linear. Defaults to “mix”.

Returns:

The resultant color.

Return type:

Color

to_tuple()[source]#

Converts the Color to a tuple.

Returns:

The tuple representing the color.

Return type:

tuple(int, int, int, int)

to_hex()[source]#

Converts the Color to a hexadecimal string.

Returns:

The hexadecimal output in lowercase. (i.e. ffffffff)

Return type:

str

classmethod from_rgba32(rgba32)[source]#

Creates a Color from an RGBA32 representation.

Parameters:

rgba32 (int) – The RGBA32 representation as an int.

Returns:

The color object from the RGBA32.

Return type:

Color

classmethod from_hex(h)[source]#

Creates an Color from a hex string.

Parameters:

h (str) – The hexadecimal value in the format “RRGGBBAA”.

Returns:

The Color value.

Return type:

Color

classmethod from_hsv(h, s, v)[source]#

Creates an Color from an HSV.

Parameters:
  • h (int) – The hue amount.

  • s (int) – The saturation amount.

  • v (int) – The value amount.

Returns:

The Color value.

Return type:

Color

class property random: Color[source]#

A random color.

Return type:

Color

class property clear: Color[source]#

A transparent color object.

Return type:

Color

class property black: Color[source]#

The default black color. To see the RGB values, check out the Grayscale defaults.

Return type:

Color

class property white: Color[source]#

The default white color. To see the RGB values, check out the Grayscale defaults.

Return type:

Color

class property night: Color[source]#

The default night color. To see the RGB values, check out the Grayscale defaults.

Return type:

Color

class property darkgray: Color[source]#

The default darkgray color. To see the RGB values, check out the Grayscale defaults.

Return type:

Color

class property gray: Color[source]#

The default gray color. To see the RGB values, check out the Grayscale defaults.

Return type:

Color

class property lightgray: Color[source]#

The default lightgray color. To see the RGB values, check out the Grayscale defaults.

Return type:

Color

class property snow: Color[source]#

The default snow color. To see the RGB values, check out the Grayscale defaults.

Return type:

Color

class property yellow: Color[source]#

The default yellow color. To see the RGB values, check out the Color defaults.

Return type:

Color

class property orange: Color[source]#

The default orange color. To see the RGB values, check out the Color defaults.

Return type:

Color

class property red: Color[source]#

The default red color. To see the RGB values, check out the Color defaults.

Return type:

Color

class property scarlet: Color[source]#

The default scarlet color. To see the RGB values, check out the Color defaults.

Return type:

Color

class property magenta: Color[source]#

The default magenta color. To see the RGB values, check out the Color defaults.

Return type:

Color

class property purple: Color[source]#

The default purple color. To see the RGB values, check out the Color defaults.

Return type:

Color

class property violet: Color[source]#

The default violet color. To see the RGB values, check out the Color defaults.

Return type:

Color

class property blue: Color[source]#

The default blue color. To see the RGB values, check out the Color defaults.

Return type:

Color

class property cyan: Color[source]#

The default cyan color. To see the RGB values, check out the Color defaults.

Return type:

Color

class property turquoize: Color[source]#

The default turquoize color. To see the RGB values, check out the Color defaults.

Return type:

Color

class property green: Color[source]#

The default green color. To see the RGB values, check out the Color defaults.

Return type:

Color

class property lime: Color[source]#

The default lime color. To see the RGB values, check out the Color defaults.

Return type:

Color

Font#

The font module for text rendering

class Font[source]#

Bases: object

This is the font object that is used to render text.

__init__(options={})[source]#
property size: int#

The size of the text in points.

Return type:

int

property color: Color#

The color of the text.

Return type:

Color

generate_surface(text, align=Defaults.text_defaults['align'], width=Defaults.text_defaults['width'])[source]#

Generate the surface containing the text.

Parameters:
  • text (str) – The text to render.

  • align (str) – The alignment to use. Defaults to Vector(0, 0).

  • width (int) – The maximum width to use. Defaults to -1.

Raises:
  • ValueError – The width is too small for the text.

  • ValueError – The size of the text is too large for the font.

Returns:

The surface containing the text.

Return type:

sdl2.SDL_Surface

add_style(style)[source]#

Adds a style to the font.

Parameters:

style (str) – The style to add. Can be one of the following: bold, italic, underline, strikethrough.

remove_style(style)[source]#

Removes a style from the font.

Parameters:

style (str) – The style to remove. Can be one of the following: bold, italic, underline, strikethrough.

apply_styles()[source]#

Applies the styles to the font.

Radio#

The Radio module is a system used to communicate to all parts of the game. This is similar to event systems in other game engines.

To use this, first you need to listen for a specific key using the Radio.listen() function. Then from anywhere else in the code, you can broadcast that event key using Radio.broadcast().

Go here to see all the events that can be broadcast.

class Radio[source]#

Bases: object

Broadcast system manages all events and inter-class communication. Handles event callbacks during the beginning of each Game.update() call.

listeners#

A dictionary with all of the active listeners.

Type:

dict[str, Callable]

classmethod listen(event, func)[source]#

Creates an event listener and registers it.

Parameters:
  • event (str) – The event key to listen for.

  • func (Callable) – The function to run once the event is broadcast. It may take in a params dictionary argument.

classmethod register(listener)[source]#

Registers an event listener.

Parameters:

listener (Listener) – The listener object to be registered

classmethod broadcast(event, params={})[source]#

Broadcast an event to be caught by listeners.

Parameters:
  • event (str) – The event key to broadcast.

  • params – The event parameters (usually a dictionary)

class Listener[source]#

Bases: object

The actual listener object itself. A backend class for the Radio.

event#

The event descriptor

Type:

str

callback#

The function called when the event occurs

Type:

Callable

registered#

Describes whether the listener is registered

Type:

bool

__init__(event, callback)[source]#
ping(params)[source]#

Calls the callback of this listener.

Parameters:

params – The event parameters (usually a dictionary)

remove()[source]#

Removes itself from the radio register.

Raises:

ValueError – Raises error when listener is not registered

Errors#

Some custom errors

exception Error[source]#

Bases: Exception

A basic rubato Error.

exception IdError[source]#

Bases: Exception

An error that is raised when an invalid ID is used.

exception SideError[source]#

Bases: Exception

An error that is raised when the number of sides is invalid

exception DuplicateComponentError[source]#

Bases: Exception

An error that is raised when you try to add a component to a game object that already has a component of the same type

exception ComponentNotAllowed[source]#

Bases: Exception

An error that is raised when you try to add a component on a game object that is not allowed by another component on that game object.