All About Sprites

Sprites are game objects.

In ppb all sprites are built from composition via mixins or subclassing via traditional Python inheritance. Sprite is provided as a default expectation used in ppb.

If you intend to build your own set of expectation, see BaseSprite.

Default Sprite

This is the class you should instantiate or subclass for your games unless you are changing the defaults.

class ppb.Sprite(**kwargs)[source]

The default Sprite class.

Sprite includes:

  • BaseSprite
  • SquareShapeMixin
  • RenderableMixin
  • RotatableMixin

New in 0.7.0: Use this in place of BaseSprite in your games.

bottom

The bottom side

center

The position of the center of the sprite

facing

The direction the “front” is facing

left

The left side

right

The right side

rotate(degrees)

Rotate the sprite by a given angle (in degrees).

rotation

The amount the sprite is rotated, in degrees

top

The top side

Note that ppb.BaseSprite is deprecated in favor of ppb.Sprite. Scheduled for removal in ppb v0.8.0.

Feature Mixins

These mixins are the various features already available in Sprite. Here for complete documentation.

class ppb.sprites.RenderableMixin[source]

A class implementing the API expected by ppb.systems.renderer.Renderer.

You should include RenderableMixin before BaseSprite in your parent class definitions.

image = None

(ppb.Image): The image asset

class ppb.sprites.RotatableMixin[source]

A simple rotation mixin. Can be included with sprites.

basis = Vector(0.0, -1.0)

The baseline vector, representing the “front” of the sprite

facing

The direction the “front” is facing

rotate(degrees)[source]

Rotate the sprite by a given angle (in degrees).

rotation

The amount the sprite is rotated, in degrees

class ppb.sprites.SquareShapeMixin(**kwargs)[source]

A mixin that applies square shapes to sprites.

You should include SquareShapeMixin before ppb.sprites.BaseSprite in your parent classes.

bottom

The bottom side

center

The position of the center of the sprite

left

The left side

position = None

Just here for typing and linting purposes. Your sprite should already have a position.

right

The right side

size = 1

The width/height of the sprite (sprites are square)

top

The top side

Base Classes

The base class of Sprite, use this if you need to change the low level expectations.

class ppb.sprites.BaseSprite(**kwargs)[source]

The base Sprite class. All sprites should inherit from this (directly or indirectly).

The things that define a BaseSprite:

  • A position vector
  • A layer

BaseSprite provides an __init__() method that sets attributes based on kwargs to make rapid prototyping easier.

layer = 0

The layer a sprite exists on.

position = Vector(0.0, 0.0)

(ppb.Vector): Location of the sprite

Internals

These classes are internals for various APIs included with mixins.

class ppb.sprites.Side(parent: ppb.sprites.SquareShapeMixin, side: str)[source]

Acts like a float, but also has a variety of accessors.

bottom

Get the corner vector

center

Get the midpoint vector

left

Get the corner vector

right

Get the corner vector

top

Get the corner vector