NAME

SDL::Sprite - Parrot class representing sprites in Parrot SDL

SYNOPSIS

    # load this library
    load_bytecode 'library/SDL/Sprite.pir'

    # ... load a new SDL::Image into image

    # create a new SDL::Sprite object
    .local pmc sprite
    sprite = new 'SDL::Sprite'

    # set the sprite's arguments
    sprite.'init'( 'surface'  => image, 'source_x' =>     0, 'source_y' =>     0, 'dest_x'   =>   270, 'dest_y'   =>   212, 'bgcolor'  => black )


    # if the image has multiple tiles that represent animation frames, set the
    # width and height of each tile
    # 'width'    =>   100, 'height'   =>    56

    # ... draw the sprite to surfaces as you will

DESCRIPTION

A SDL::Sprite object represents an image and its position. By changing the coordinates of the sprite, you'll change its position when it draws itself to a surface.

This is a class in progress; it has to represent several different drawing styles.

METHODS

A SDL::Sprite object has the following methods:

init( 'arg' => pairs )
Given argument key-value pairs, sets the attributes of this object. The useful keys are as follows:
surface
The SDL::Image from which to draw the sprite frames.
source_x
The x coordinate within the surface from which to start drawing.
source_y
The y coordinate within the surface from which to start drawing.
dest_x
The x coordinate within the destination surface to which to draw.
dest_y
The y coordinate within the destination surface to which to draw.
bgcolor
A SDL::Color object representing the background color of the main surface. This will come in handy when drawing over the previous position of this sprite, unless you redraw the entire surface on every frame.
width
The width of the image, in pixels, to draw. If you have multiple frames of an animation within the image provided, set the width here to the width of a single frame.If you don't set this value, this will use the current width of the image.
height
The height of the image, in pixels, to draw. If you have multiple frames of an animation within the image provided, set the height here to the height of a single frame.If you don't set this value, this will use the current height of the image.
Note: I'm not completely thrilled with these arguments, so they may change slightly.
draw_undraw( surface )
Draws the image this object represents to the given SDL::Surface. This will return two SDL::Rect objects, one representing the previous position of this sprite and one representing the current position.Use this when dealing with a single-buffered main window. You'll need to call update_rect() on the surface to make things actually show up, if it's the main surface.Note that this will fill in the previous position with the background color set in the constructor.
draw( surface )
Draws the image represented by this object to the given surface. This will also fill the previous position of the image with the background color. (Arguably, this is not always right, but I know about it and will figure something out, unless you have a better idea and let me know first.)Use this when dealing with a double-buffered main window. In that case, you will have to call flip() on the surface yourself to make your changes appear.
surface()
Returns the underlying surface of the image represented by this class. You should never need to call this directly, unless you're working with the raw SDL functions.
source_rect()
Returns the SDL::Rect object representing the source from which to draw within the underlying image.You should never need to call this directly.
prev_rect()
Returns the SDL::Rect representing the previous position of this sprite within a destination surface.You should never need to call this directly.
rect()
Returns the SDL::Rect representing this sprite's current position within the destination surface.You should never need to call this directly.
bgcolor()
Returns the SDL::Color object representing the background color to draw to the destination when undrawing the previous position of this sprite.You should never need to call this directly.
drawn_rect()
Returns the SDL::Rect representing the current position of the sprite within the destination surface as of the current drawing operation.You should never need to call this directly. I mean it. This may go away suddenly in a brilliant flash of insight.
undrawn_rect()
Returns the SDL::Rect representing the previous position of the sprite within the destination surface as of the current drawing operation.You should never need to call this directly. I mean it. This may go away suddenly in a brilliant flash of insight.
x( [ new_x_coordinate ] )
Gets and sets the x coordinate of this sprite within the destination surface, in pixels. This is always an integer.
y( [ new_y_coordinate ] )
Gets and sets the y coordinate of this sprite within the destination surface, in pixels. This is always an integer.
x_velocity( [ new_x_velocity ] )
Gets and sets the x velocity of this sprite. This is always an integer.Maybe this method shouldn't be here; it may move.
y_velocity( [ new_y_velocity ] )
Gets and sets the y velocity of this sprite. This is always an integer.Maybe this method shouldn't be here; it may move.

AUTHOR

Written and maintained by chromatic, <chromatic at wgz dot org>, with suggestions from Jens Rieks. Please send patches, feedback, and suggestions to the Perl 6 Internals mailing list.

COPYRIGHT

Copyright (C) 2004-2008, Parrot Foundation.