Package pajammin :: Package display :: Package sprite :: Module sprite :: Class Sprite
[show private | hide private]
[frames | no frames]

Type Sprite

 object --+    
          |    
WorldWidget --+
              |
             Sprite

Known Subclasses:
Iso3dSprite

A graphical widget that defines one or more animation modes, based on images loaded from files. An animation mode is a sequence of one or more images, along with information about how long each one should be displayed. Note that a still image can be encoded as animation mode with one image.

A sprite's location is defined by its anchor, which is typically the center of its image. A sprite's anchor can be read and modified via the x and y attributes. When a sprite changes animation modes, the new animation mode's anchor is put at the same position as the old animation mode's anchor.

The images that a sprite uses are defined by its sprite category, which describes one or more animations that the sprite can use. The current animation is determined by the sprite's animation attribute. The speed with which the animation will be cycled is specified by the animation_speed attribute. The animation can also be manually cycled using advance_animation.
Method Summary
  __init__(self, category, x, y, animation, layer)
  __getstate__(self)
  __setstate__(self, state)
  advance_animation(self, ticks)
Advance this sprite's animation by the given number of ticks.
  animation_duration(self, animation)
What is the total time to play the current animation?
  animation_image(self, animation, framenum)
  draw(self, screen, duration, dx, dy)
Draw this widget to the screen.
  draw_scaled(self, surface, dx, dy, scalefac)
  goto_frame(self, framenum)
  has_animation(self, animation)
  move(self, dx, dy)
  move_to(self, x, y)
  num_frames(self)
  restart_animation(self)
Move this sprite's animation to its first frame.
  _getx(self)
  _gety(self)
  _set_animation(self, animation, restart)
  _set_category(self, category, animation, restart)
    Inherited from object
  __delattr__(...)
x.__delattr__('name') <==> del x.name
  __getattribute__(...)
x.__getattribute__('name') <==> x.name
  __hash__(x)
Return hash(x)...
  __new__(T, S, ...)
Return a new object with type S, a subtype of T...
  __reduce__(...)
helper for pickle
  __reduce_ex__(...)
helper for pickle
  __repr__(x)
Return repr(x)...
  __setattr__(...)
x.__setattr__('name', value) <==> x.name = value
  __str__(x)
Return str(x)...

Property Summary
  animation: The name of the animation sequence that is currently used by this sprite.
  category: The name of this sprite's category.
  x: The x position of this sprite's anchor.
  y: The y position of this sprite's anchor.
    Inherited from WorldWidget
  rect: A pygame Rect describing the current position of this sprite's image.

Instance Variable Summary
  animation_speed: What speed to advance the animation at, in ticks/msec.
  layer: The sprite's layer.
  _animation: The sprite's current AnimationSequence.
  _framenum: The animation frame that is currently being displayed.
  _rect: A pygame Rect recording the size and location of the sprite's image.
  _ticks: The number of ticks for which we have been displaying the current frame.
    Inherited from WorldWidget
  movement_callback: A callback method that should be called whenever the sprite is moved.
NoneType rect: A pygame Rect describing the extent of this widget, in world coordinates.

Method Details

__init__(self, category, x=0, y=0, animation=None, layer=None)
(Constructor)

Parameters:
category - The new sprite's category. The category can be specified using either a SpriteCategory object, or the name of a SpriteCategory that has been added to the sprite catalog.
x, y - The new sprite's anchor.
animation - The name of the new sprite's animation. If no animation is specified, then the category's default animation is used.
layer - An integer indicating the order in which the sprite should be drawn to the screen, relative to other sprites. Sprites with higher layer numbers will be drawn later. If no layer is specified, then the category's default layer is used.
Overrides:
__builtin__.object.__init__

__getstate__(self)

__setstate__(self, state)

advance_animation(self, ticks)

Advance this sprite's animation by the given number of ticks.

Requires: ticks >= 0

animation_duration(self, animation=None)

What is the total time to play the current animation?

animation_image(self, animation=None, framenum=0)

draw(self, screen, duration, dx, dy)

Draw this widget to the screen.
Parameters:
screen - The screen surface.
duration - The amount of time that has elapsed since the last call to draw, in msec.
dx, dy - An offset that should be added to world coordinates to give screen coordinates.
Returns:
A pygame Rect indicating what area of the screen has been modified by this draw operation.
Overrides:
pajammin.display.engine.WorldWidget.draw (inherited documentation)

draw_scaled(self, surface, dx, dy, scalefac)

goto_frame(self, framenum)

has_animation(self, animation)

move(self, dx, dy)

move_to(self, x, y)

num_frames(self)

restart_animation(self)

Move this sprite's animation to its first frame.

_getx(self)

_gety(self)

_set_animation(self, animation, restart=False)

_set_category(self, category, animation=None, restart=False)


Property Details

animation

The name of the animation sequence that is currently used by this sprite. Setting this will change to the specified animation sequence, starting on the first frame, with the animation sequence's default animation speed.
Get Method:
unknown-7609072(...)
Set Method:
_set_animation(self, animation, restart)

category

The name of this sprite's category. Modifying this variable will change the sprite to use a different category.
Get Method:
unknown-7591792(...)
Set Method:
_set_category(self, category, animation, restart)

rect

A pygame Rect describing the current position of this sprite's image. Modifying this rect will *not* change the position of the sprite -- use move() or move_to() instead. (Read-only)
Get Method:
unknown-7609712(...)

x

The x position of this sprite's anchor. (Read-only)
Get Method:
_getx(self)

y

The y position of this sprite's anchor. (Read-only)
Get Method:
_gety(self)

Instance Variable Details

animation_speed

What speed to advance the animation at, in ticks/msec. If zero, then the animation will be manually controlled.

layer

The sprite's layer.

_animation

The sprite's current AnimationSequence.

_framenum

The animation frame that is currently being displayed.

_rect

A pygame Rect recording the size and location of the sprite's image.

_ticks

The number of ticks for which we have been displaying the current frame. (Or None if the image is a non-looped image that has reached its last frame.)