Documentation Index | From module rabbyt.sprites.

BaseSprite

BaseSprite(...)

This class provides some basic functionality for sprites:

BaseSprite doesn't render anything itself You'll want to subclass it and override either render() or render_after_transform().

You can pass any of the BaseSprite properties as keyword arguments. (x, y, xy, etc.)

Methods

attrgetter

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

convert_offset((x, y)) -> (x, y)

Converts coordinates relative to this sprite to global coordinates, including rotation and scaling.

render

render()

Renders the sprite.

By default, this method will transform the OpenGL modelview matrix according to x, y, scale, and rot, and call render_after_transform().

If you want transformations to be handled for you, leave this method and override render_after_transform(). Otherwise, override render().

render_after_transform

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().

Properties

alpha

alpha color component

blue

blue color component

bounding_radius

bounding_radius

This should be the distance of the farthest point from the center. It can be used for collision detection.

bounding_radius_squared

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

green color component

red

red color component

rgb

swizzle for red, green, blue

rgba

swizzle for red, green, blue, alpha

rot

rotation angle in degrees.

scale

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.

scale_x

x component of scale

scale_y

y component of scale

x

x coordinate of the sprite

xy

swizzle for x, y

y

y coordinate of the sprite