util
—utilities for graphics¶
-
class
Spritemap
(img[, ncols][, nrows][, sw][, sh], pad=0[, nsprites], pool=conf.DEFAULT_RESOURCE_POOL, res_mgr=conf.GAME.resources)[source]¶ Bases:
object
A wrapper for spritesheets.
Parameters: - img – a surface or filename to load from; this is a grid of sprites with the same size.
- ncols,sw – determines the the number of columns in the spritesheet;
ncols
is the number of columns andsw
is the width of individual sprites, in pixels. Only one is required, and both may be omitted if the spritesheet is a single column. - nrows,sh – determines the the number of rows in the spritesheet;
nrows
is the number of rows andsh
is the height of individual sprites. Only one is required, and both may be omitted if the spritesheet is a single row. - pad – padding in pixels between each sprite. This may be
(col_gap, row_gap)
, or a single number for the same gap in both cases. - nsprites – the number of sprites in the spritesheet. If omitted, this is taken to be the maximum number of sprites that could fit on the spritesheet; if passed, and smaller than the maximum, the last sprites are ignored (see below for ordering).
- pool –
ResourceManager
resource pool name to cache any loaded images in. - res_mgr –
ResourceManager
instance to use to load any images.
A spritemap provides
__len__
and__getitem__
to obtain sprites, and so iterating over all sprites is also supported. Sprites are obtained from top to bottom, left to right, in that order, and slices are as follows:spritemap[sprite_index] -> sfc spritemap[col, row] -> sfc
where
sfc
is a surface containing the sprite. (The latter form is an implicittuple
, sospritemap[(col, row)]
works as well.)-
sprite_w
= None¶ The width of each sprite, in pixels.
-
sprite_h
= None¶ The height of each sprite, in pixels.