Stage – a Tile and Sprite Engine¶
Stage is a library that lets you display tile grids and sprites on SPI-based RGB displays in CircuitPython. It is mostly made with video games in mind, but it can be useful in making any kind of graphical user interface too.
For performance reasons, a part of this library has been written in C and has
to be compiled as part of the CircuitPython firmware as the _stage
module.
For memory saving reasons, it’s best if this library is also included in the
firmware, as a frozen module.
API Reference¶
The API reference is available at http://circuitpython-stage.readthedocs.io.
stage¶
- class stage.Bank(buffer=None, palette=None)[source]¶
Store graphics for the tiles and sprites.
A single bank stores exactly 16 tiles, each 16x16 pixels in 16 possible colors, and a 16-color palette. We just like the number 16.
- class stage.Grid(bank, width=8, height=8, palette=None, buffer=None)[source]¶
A grid is a layer of tiles that can be displayed on the screen. Each square can contain any of the 16 tiles from the associated bank.
- class stage.Sprite(bank, frame, x, y, z=0, rotation=0, palette=None)[source]¶
A sprite is a layer containing just a single tile from the associated bank, that can be positioned anywhere on the screen.
- set_frame(frame=None, rotation=None)[source]¶
Set the current graphic and rotation of the sprite.
The possible values for rotation are: 0 - none, 1 - 90 degrees clockwise, 2 - 180 degrees, 3 - 90 degrees counter-clockwise, 4 - mirrored, 5 - 90 degrees clockwise and mirrored, 6 - 180 degrees and mirrored, 7 - 90 degrees counter-clockwise and mirrored.
- class stage.Stage(display, fps=6, scale=None)[source]¶
Represents what is being displayed on the screen.
The
display
parameter is displayio.Display representing an initialized display connected to the device.The
fps
specifies the maximum frame rate to be enforced.The
scale
specifies an optional scaling up of the display, to use 2x2 or 3x3, etc. pixels. If not specified, it is inferred from the display size (displays wider than 256 pixels will have scale=2, for example).
- class stage.Text(width, height, font=None, palette=None, buffer=None)[source]¶
Text layer. For displaying text.
- class stage.WallGrid(grid, walls, bank, palette=None)[source]¶
A special grid, shifted from its parents by half a tile, useful for making nice-looking corners of walls and similar structures.
ugame¶
- ugame.display¶
An initialized display, that can be used for creating Stage objects.
- ugame.buttons¶
An instance of
GamePad
or other similar class, that has aget_pressed
method for retrieving a bit mask of pressed buttons. That value can be then checked with & operator against the constants:K_UP
,K_DOWN
,K_LEFT
,K_RIGHT
,K_X
,K_O
and on some platforms also:K_START
andK_SELECT
.
- ugame.audio¶
And instance of the
Audio
or other similar class, that hasplay
,stop
andmute
methods.