Sprite(texture=None, shape=None, tex_shape=(0,1,1,0), ...)
This class provides a basic, four point, textured sprite.
All arguments are optional.
texture should be an image filename, a pyglet texture object, or an OpenGL texture id. (See Sprite.texture for more information.)
If shape is not given it will default to the dimensions of the texture if they are available. For more information on shape and tex_shape read the docstrings for Sprite.shape and Sprite.tex_shape
Additionally, you can pass values for most of the properties as keyword arguments. (x, y, xy, u, v, uv, etc...)
attrgetter(name)
Returns an anim that returns the value of the given attribute name.
Perhaps this is easiest to see with an example. The following two lines will both do the same thing, only the second is much, much faster:
sprite.x = lambda: other_sprite.x sprite.x = other_sprite.attrgetter("x")
The anim returned by attrgetter is implemented in C and will retrieve the value without doing a python attribute lookup.
This works for any attribute that you can assign an anim to.
swizzle descriptors are properly handled.
convert_offset((x, y)) -> (x, y)
Converts coordinates relative to this sprite to global coordinates, including rotation and scaling.
render_after_transform()
This method is called by BaseSprite.render() after transformations have been applied.
If you don't want to mess with doing transformations yourself, you can override this method instead of render().
alpha color component
blue color component
y coordinate of the bottom of the sprite
bounding_radius
This should be the distance of the farthest point from the center. It can be used for collision detection.
By default this is calculated from the shape property, and is automatically updated whenever the shape is updated. However, you can set it explicitly yourself.
After the value is explicitly set it will no longer be updated by changes to the shape. To revert back to the default behavior, delete the property using the del statement:
del sprite.bounding_radius
bounding_radius_squared
This is just like bounding_radius, only it's squared. (duh)
bounding_radius and bounding_radius_squared are automatically kept in sync with each other.
green color component
x coordinate of the left side of the sprite
red color component
swizzle for red, green, blue
swizzle for red, green, blue, alpha
x coordinate of the right side of the sprite
rotation angle in degrees.
scale
1.0 is normal size; 0.5 is half size, 2.0 is double size... you get the point.
You can scale the x and y axes independently by assigning a tuple with a length of two.
x component of scale
y component of scale
The shape of the sprite.
This must either be of the form [left, top, right, bottom], or a list of four coordinates, eg. [(0,0), (20,0), (20,20), (0,20)]
[-10, -10, 10, 10] is the default.
When you assign to shape, bounding_radius is automatically set to the distance of the farthest coordinate.
This defines how a texture is mapped onto the sprite.
Like Sprite.shape, you can give either [left, top, right, bottom] or a list of coordinates.
The default is [0, 1, 1, 0], which uses the entire texture.
For easy integration with pyglet, a tuple with four items will be interpreted as the format used by the tex_coords attribute of pyglet textures.
Sprite.texture
The texture used for this sprite.
The value can be in a variety of formats:
If it's a string, it will be used as a filename to load the texture.
If it's an integer, it will be used as an OpenGL texture id.
If it's an object with an id attribute, it will be treated as a pyglet texture object. (The width, height, and tex_coords attributes will set the sprite's shape and tex_shape properties.)
y coordinate of the top of the sprite
texture offset
swizzle for u, v
texture offset
x coordinate of the sprite
swizzle for x, y
y coordinate of the sprite