Documentation Index

# rabbyt

Rabbyt is a fast 2d sprite library for Python.

## Modules

- rabbyt.sprites
- rabbyt.anims
- rabbyt.primitives
- rabbyt.collisions

## Classes

- Scheduler

## Functions

### set_viewport

`set_viewport(viewport, [projection])`

Sets how coordinates map to the screen.

`viewport` gives the screen coordinates that will be drawn to. It should be in either the form `(width, height)` or `(left, top, right, bottom)`

`projection` gives the sprite coordinates that will be mapped to the screen coordinates given by `viewport`. It too should be in one of the two forms accepted by `viewport`. If `projection` is not given, it will default to the width and height of `viewport`. If only the width and height are given, `(0, 0)` will be the center point.

### set_default_attribs

`set_default_attribs()`

Sets a few of the OpenGL attributes that sprites expect.

Unless you know what you are doing, you should call this at least once before rendering any sprites. (It is called automatically in `rabbyt.init_display()`)

### clear

`clear(rgba=(0.0,0.0,0.0,1.0))`

Clear the screen to a background color.

### get_gl_vendor

`gl_get_vendor()`

Returns the OpenGL vendor string. Returns None if there is no context.

### render_unsorted

`render_unsorted(sprites)`

Renders a list of sprites.

Since this function is implemented in Pyrex, it should be a little faster than looping through the sprites in Python.

### load_texture

`load_texture(byte_string, size, type='RGBA', filter=True, mipmap=True)`

Load a texture and return it.

### update_texture

`update_texture(texture_id, byte_string, size, type='RGBA', filter=True, mipmap=True)`

Update a texture with a different byte_string.

### unload_texture

`unload_texture(texture_id)`

Unload a texture from memory.

### autodetect_load_texture

`autodetect_load_texture(filename)`

Automatically chooses between pyglet and pygame for loading a texture.

If pyglet is importable and pyglet.gl.get_current_context() does not return None, pyglet will be used. Otherwise, pygame is used.

After this function is called the first time, it automatically calls `set_load_texture_file_hook` with the correct function, so there is no additional overhead.

This is the default function for loading textures.

### pyglet_load_texture

`pyglet_load_texture(filename)`

Uses pyglet to load a texture from a file. The texture is cached.

(This is meant to be used with `set_load_texture_file_hook`.)

### pygame_load_texture

`pygame_load_texture(filename, filter=True, mipmap=True) -> texture_id, size`

Reads an image from a file and loads it as a texture. Pygame is used for reading the image.

If `filename` is a relative path, the working directory is searched first, then `rabbyt.data_directory` is searched for the file.

### set_load_texture_file_hook

`set_load_texture_file_hook(callback)`

This sets the `callback` that is used to load a texture from a file. (It is called when you give a string for the first argument of `Sprite`.)

The default is `rabbyt.autodetect_load_texture`, which will smartly choose between using pyglet of pygame to load the file.

The `callback` should take the filename as a single argument, and return either a tuple of the form `(texture_id, (width, height))` or any value suitable for assiging to `Sprite.texture`.

### init_display

In an ongoing attempt at cleaning up rabbyt, init_display has been deprecated and will be removed in a future version. You can achive the same result by doing this:

    pygame.init()
    pygame.display.set_mode(size, pygame.OPENGL | pygame.DOUBLEBUF)
    rabbyt.set_viewport(size)
    rabbyt.set_default_attribs()