tuxemon.sprite module

class tuxemon.sprite.CaptureDeviceSprite(*, tray, monster, sprite, state)[source]

Bases: Sprite

Parameters:
  • tray (Sprite) –

  • monster (Optional[Monster]) –

  • sprite (Sprite) –

  • state (str) –

animate_capture(animate)[source]

Animates the capture device in game.

Parameters:

animate (Callable[[...], object]) – The animation function.

Return type:

None

update_state()[source]

Updates the state of the capture device.

Returns:

The new state.

Return type:

str

class tuxemon.sprite.MenuSpriteGroup(*, default_layer=0)[source]

Bases: SpriteGroup[_MenuElement]

Sprite Group to be used for menus.

Includes functions for moving a cursor around the screen.

arrange_menu_items()[source]

Iterate through menu items and position them in the menu.

Return type:

None

determine_cursor_movement(index, event)[source]

Given an event, determine a new selected item offset.

You must pass the currently selected object. The return value will be the newly selected object index.

Parameters:
  • index (int) – Index of the item in the list.

  • event (PlayerInput) – Player event that may cause to select another menu item.

Returns:

New menu item offset.

Return type:

int

expand = False
class tuxemon.sprite.RelativeGroup(*, parent, **kwargs)[source]

Bases: MenuSpriteGroup[_MenuElement]

Drawing operations are relative to the group’s rect.

calc_absolute_rect(rect)[source]
Parameters:

rect (Rect) –

Return type:

Rect

draw(surface)[source]

draw all sprites in the right order onto the passed surface

LayeredUpdates.draw(surface): return Rect_list

Parameters:

surface (Surface) –

Return type:

List[Rect]

rect = <rect(0, 0, 0, 0)>
update_rect_from_parent()[source]
Return type:

None

class tuxemon.sprite.Sprite(*args, image=None, animation=None)[source]

Bases: DirtySprite

Parameters:
  • args (pygame.sprite.Group) –

  • image (Optional[pygame.surface.Surface]) –

  • animation (Optional[SurfaceAnimation]) –

property animation: SurfaceAnimation | None
draw(surface, rect=None)[source]

Draw the sprite to the surface.

This operation does not scale the sprite, so it may exceed the size of the area passed.

Parameters:
  • surface (Surface) – Surface to be drawn on.

  • rect (Rect | None) – Area to contain the sprite.

Returns:

Area of the surface that was modified.

Return type:

Rect

property height: int
property image: Surface
property rect: Rect
property rotation: int
update(time_delta=0, *args, **kwargs)[source]

method to control sprite behavior

Sprite.update(*args, **kwargs):

The default implementation of this method does nothing; it’s just a convenient “hook” that you can override. This method is called by Group.update() with whatever arguments you give it.

There is no need to use this method if not using the convenience method by the same name in the Group class.

Parameters:
  • time_delta (float) –

  • args (Any) –

  • kwargs (Any) –

Return type:

None

update_image()[source]
Return type:

None

property width: int
class tuxemon.sprite.SpriteGroup(*, default_layer=0)[source]

Bases: LayeredUpdates, Generic[_GroupElement]

Sane variation of a pygame sprite group.

Features: * Supports Layers * Supports Index / Slice * Supports skipping sprites without an image * Supports sprites with visible flag * Get bounding rect of all children

add(*sprites, **kwargs)[source]

add a sprite or sequence of sprites to a group

LayeredUpdates.add(*sprites, **kwargs): return None

If the sprite you add has an attribute _layer, then that layer will be used. If **kwarg contains ‘layer’, then the passed sprites will be added to that layer (overriding the sprite._layer attribute). If neither the sprite nor **kwarg has a ‘layer’, then the default layer is used to add the sprites.

Parameters:
  • sprites (Sprite) –

  • kwargs (Any) –

Return type:

None

calc_bounding_rect()[source]

A rect object that contains all sprites of this group.

Return type:

Rect

sprites()[source]

return a ordered list of sprites (first back, last top).

LayeredUpdates.sprites(): return sprites

Return type:

Sequence[_GroupElement]

class tuxemon.sprite.VisualSpriteList(**kwargs)[source]

Bases: RelativeGroup[_MenuElement]

Sprite group which can be configured to arrange the children sprites into columns.

add(*sprites, **kwargs)[source]

Add something to the stacker.

Do not add iterables to this function. Use ‘extend’.

Parameters:
  • item – Stuff to add.

  • sprites (Sprite) –

  • kwargs (Any) –

Return type:

None

arrange_menu_items()[source]

Iterate through menu items and position them in the menu. Defaults to a multi-column layout with items placed horizontally first.

Return type:

None

calc_bounding_rect()[source]

A rect object that contains all sprites of this group.

Return type:

Rect

clear()[source]

erase the previous position of all sprites

Group.clear(surface, bgd): return None

Clears the area under every drawn sprite in the group. The bgd argument should be Surface which is the same dimensions as the screen surface. The bgd could also be a function which accepts the given surface and the area to be cleared as arguments.

Return type:

None

property columns: int
draw(surface)[source]

draw all sprites in the right order onto the passed surface

LayeredUpdates.draw(surface): return Rect_list

Parameters:

surface (Surface) –

Return type:

List[Rect]

expand = True
orientation: Literal['horizontal'] = 'horizontal'
remove(*items)[source]

remove sprite(s) from group

Group.remove(sprite, list, or group, …): return None

Removes a sprite or sequence of sprites from a group.

Parameters:

items (Sprite) –

Return type:

None