About | Download | Reference | Tutorial | Email the Creator

PygAnimation Class

Constructor

pyganim.PygAnimation(frames, loop=True)

The frames parameter is a list of tuples. Each tuple is either of the format (str_image_filename, float/int_duration) or (pygame.Surface, float/int_duration).

The new PygAnimation object is created in a stopped state.

Attributes

state

The state attribute can be set to one of pyganim.PLAYING, pyganim.PAUSED, or pyganim.STOPPED. Assigning these values to the state attribute has the same effect as calling the play(), pause(), and stop() methods respectively.

loop

A boolean value. If True, the animation continues back to the beginning after playing through the last frame. If False, then after playing the last frame the state switches to pyganim.STOPPED.

rate

A floating point number that shows how fast the animatio plays. At 1.0, the animation plays at normal speed (i.e. the durations originally passed to the constructor). If set to, for example, 2.0 then the animation plays twice as fast. If set to 0.25 then the animation plays at one quarter speed.

visibility

A boolean value. If True, the frame is drawn when the blit methods are called. If False, then the frames are not drawn when the blit methods are called.

elapsed

A floating point number that shows how far the animation has played. If this attribute is read as 4.0, then the animation is currently four seconds in. If this attribute is set to 6.5, then the animation is set to six and half seconds in.

Methods

anchor(anchorpoint=NORTHWEST)

If the images provided are not the same size, then the anchor() method can set them to be the same size. The new width and height will be the maximum width and height of all the frames in the PygAnimation object. The anchorpoint parameter dictates where the extra space should be added to each image. It can be one of the following constants in pyganim.py: NORTHWEST, NORTH, NORTHEAST, WEST, CENTER, EAST, SOUTHWEST, SOUTH, SOUTHEAST.

For example, say an animation had three frames with the following sizes:

If anchor() is called with the pyganim.NORTHWEST argument passed, the new width will be set to the width of the green frame (since it is the widest) and the height of the red frame (since it is the tallest). The NORTHWEST anchor point shoves the images as far left and up as they can go. The black represents the transparent excess space of the new frames:

If anchor() is called with the pyganim.EAST argument passed, then the images will be shoved as far right as they can (and vertically centered):

areFramesSameSize()

Return True if all the frames in this PygAnimation object have the same width and height. Otherwise, returns False.

blit(destSurface, dest)

This method is similar to the pygame.Surface.blit() method. It draws the current frame of the PygAnimation object to the pygame.Surface object passed for destSurface and with the top left corner at position dest.

blitFrameAtTime(elapsed, destSurface, dest)

Unlike the blit() method, blitFrameAtTime() will draw the frame that is current at "elapsed" seconds into the animation (instead of the "current" frame).

blitFrameNum(frameNum, destSurface, dest)

Unlike the blit() method, blitFrameNum() draws the specified frame passed (instead of the "current" frame).

convert() (pygame.Surface wrapper)

Calls the convert() on all the Surface objects in this animation.

convert_alpha() (pygame.Surface wrapper)

Calls the convert_alpha() on all the Surface objects in this animation.

clearTransforms()

All the transformations done with the PygAnimation methods (such as scale() or rotate()) can be undone by calling clearTransforms(). This will revert the frames back to ones that were originally passed to the constructor function.

fastForward(seconds=None)

This method moves the elapsed time ahead by the seconds passed. If no argument is past, the elapsed time is fast forwarded to the very end of the animation.

flip(boolx, booly) (pygame.Surface wrapper)

Calls the flip() on all the Surface objects in this animation.

getCopies(numCopies=1)

Returns a list of PygAnimation objects with the same frames and durations as this PygAnimation object. These copies can have play(), pause() and other methods called on them independently since they track their own elapsed times. The numCopies parameter specifies how many PygAnimation objects to return in the list.

getCopy()

Returns a single PygAnimation object with the same frames and durations as this PygAnimation object.

getCurrentFrame()

Returns a pygame.Surface object of the frame that would be drawn at the current elapsed time. If the current state is pyganim.STOPPED, then the first frame's pygame.Surface object is returned.

getFrame(frameNum)

Returns a specific pygame.Surface object of the frame at index frameNum.

getMaxSize()

Returns a tuple of integers formatted as (width, height) of the largest width and largest height across all frames in this PygAnimation object.

getRect()

Returns a pygame.Rect object with width and height of the largest width and largest height across all frames in this PygAnimation object. The top and left attributes of the Rect object are set to 0, 0.

isFinished()

Returns True if the elapsed time is passed the end of the entire animation. If the loop attribute is set to True, then this method will always return False.

lock() (pygame.Surface wrapper)

Calls the lock() on all the Surface objects in this animation.

makeTransformsPermanent()

All of the transformation methods (such as scale() and rotate()) can have their effects undone by calling the clearTransforms() method. However, if makeTransformsPermanent() is called, then calling clearTransforms() method will revert the frames to the state that they were when makeTransformsPermanent() was last called.

nextFrame(jump=1)

Calls the nextFrame() on all the Surface objects in this animation.

pause(startTime=None)

Pauses the animation so that the elapsed time does not progress. If an argument is passed for startTime, then the PygAnimation object will be set as though pause() had been called at that time. The startTime argument should be the number of seconds since the UNIX epoch (like time.time() returns).

prevFrame(jump=1)

Calls the prevFrame() on all the Surface objects in this animation.

play(startTime=None)

Begins playing the animation. If an argument is passed for startTime, then the PygAnimation object will be set as though play() had been called at that time. The startTime argument should be the number of seconds since the UNIX epoch (like time.time() returns).

reverse()

Reverses the order of the frames, while keeping their durations the same.

rewind(seconds=None)

Calls the rewind() on all the Surface objects in this animation.

rotate(angle) (pygame.Surface wrapper)

Calls the rotate() on all the Surface objects in this animation.

rotozoom(angle, scale) (pygame.Surface wrapper)

Calls the rotozoom() on all the Surface objects in this animation.

scroll(dx=0, dy=0) (pygame.Surface wrapper)

Calls the scroll() on all the Surface objects in this animation.

set_alpha(value=None, flags=0) (pygame.Surface wrapper)

Calls the set_alpha() on all the Surface objects in this animation.

set_clip(rect=None) (pygame.Surface wrapper)

Calls the set_clip() on all the Surface objects in this animation.

set_colorkey(Color=None, flags=0) (pygame.Surface wrapper)

Calls the set_colorkey() on all the Surface objects in this animation.

scale(width_height) (pygame.Surface wrapper)

Calls the scale() on all the Surface objects in this animation.

scale2x() (pygame.Surface wrapper)

Calls the scale2x() on all the Surface objects in this animation.

smoothscale(width_height) (pygame.Surface wrapper)

Calls the smoothscale() on all the Surface objects in this animation.

stop()

togglePause()

If the current state is pyganim.PLAYING, then togglePause() has the same effect as calling pause(). If the state is pyganim.PAUSED or pyganim.STOPPED, then togglePause() has the same effect as calling play(). The togglePause() method does not have a startTime keyword parameter.

unlock() (pygame.Surface wrapper)

Calls the unlock() on all the Surface objects in this animation.

PygConductor Class

Constructor

pyganim.PygConductor(*animations)

The PygConductor constructor gets passed a list, tuple, or dict of PygAnimation objects. It can also be passed several PygAnimation arguments as well. Although internally PygConductor stores these in a list, the ordering doesn't matter.

Attributes

animations

The animations attribute is a list of all the PygAnimation objects that this conductor controls. To add or remove PygAnimation objects, modify the items in this list.

Methods

The rest of the methods are the same as the ones in the PygAnimation class. Calling these methods on a PygConductor will call them on all the PygAnimations controlled by the conductor: