gale.frames module

This file contains generate_frames, slicing a spritesheet (one image holding a regular grid of same-sized sprites, optionally with a margin around it and/or spacing between sprites) into the list of pygame.Rects each individual sprite occupies within it.

Author: Alejandro Mujica (aledrums@gmail.com)

gale.frames.generate_frames(spritesheet, sprite_width, sprite_height, margin=0, spacing=0)[source]

Given a spritesheet, this functions builds a list of frames based on the spritesheet dimensions, the width of each sprite, and the height of each sprite.

Parameters:
  • spritesheed – surface with the texture.

  • sprite_width (int) – width of the sprite.

  • sprite_height (int) – height of the sprite.

  • margin (int) – Empty pixels around the whole spritesheet, before the first row/column of sprites. The default value is 0. Matches the “margin” a tileset exported from Tiled (https://www.mapeditor.org/) may have.

  • spacing (int) – Empty pixels between adjacent sprites, both horizontally and vertically. The default value is 0. Matches the “spacing” a tileset exported from Tiled may have.

  • spritesheet (Surface)

Return type:

List[Rect]