wsp::Sprite Class Reference

A basic drawable object with animation support. More...

#include <sprite.h>

Inheritance diagram for wsp::Sprite:

wsp::Layer

List of all members.

Public Member Functions

 Sprite ()
 Constructor.
virtual ~Sprite ()
 Destructor.
void SetImage (Image *image, u32 frameWidth=0, u32 frameHeight=0)
const ImageGetImage () const
void SetTransform (u8 transform)
u8 GetTransform () const
void SetRotation (f32 rotation)
f32 GetRotation () const
void SetZoom (f32 zoom)
f32 GetZoom () const
void SetStretchWidth (f32 stretchWidth)
void SetStretchHeight (f32 stretchHeight)
f32 GetStretchWidth () const
f32 GetStretchHeight () const
void SetTransparency (u8 alpha)
u8 GetTransparency () const
void DefineCollisionRectangle (f32 x, f32 y, f32 width, f32 height)
const RectangleGetCollisionRectangle () const
bool CollidesWith (const Rectangle *rect, f32 x=0, f32 y=0) const
bool CollidesWith (const Sprite *sprite, bool complete=false) const
bool CollidesWith (const TiledLayer *tiledlayer) const
u32 GetFrame () const
u32 GetFrameSequencePos () const
u32 GetFrameSequenceLength () const
u32 GetRawFrameCount () const
void SetFrame (u32 sequenceIndex)
void NextFrame ()
void PrevFrame ()
void SetFrameSequence (u32 *sequence, u32 length)
void Draw (f32 offsetX=0, f32 offsetY=0) const
 Draws the Sprite.


Detailed Description

A basic drawable object with animation support.

Member Function Documentation

void wsp::Sprite::SetImage ( Image image,
u32  frameWidth = 0,
u32  frameHeight = 0 
)

Assigns this sprite to an image. If there is already an image with the same size, no data gets changed.

Parameters:
image The image for this sprite.
frameWidth The width of the frame. Should be a multiple of image->GetWidth() or 0 if it should get the same width as the image.
frameHeight The height of the frame. Should be a multiple of image->GetHeight() or 0 if it should get the same height as the image.

const Image* wsp::Sprite::GetImage (  )  const

Gets the assigned image.

Returns:
A pointer to the image. NULL if no image was assigned.

void wsp::Sprite::SetTransform ( u8  transform  ) 

Changes the transformation of the texture.

Parameters:
transform The new transformation for the texture. Use the TRANSFORMATION enum members as flags, e.g. (TRANS_MIRROR | TRANS_BILINEAR_OFF)

u8 wsp::Sprite::GetTransform (  )  const

Gets the texture transformation.

Returns:
The transformation of the texture as a flag.

void wsp::Sprite::SetRotation ( f32  rotation  ) 

Sets the rotation angle of the sprite.

Parameters:
rotation The new angle of the sprite. It is measured in degrees/2, so if 90 degrees is wanted, 45 degrees should be the passed parameter.

f32 wsp::Sprite::GetRotation (  )  const

Gets the rotation angle of the sprite.

Returns:
The current angle of the sprite.

void wsp::Sprite::SetZoom ( f32  zoom  ) 

Sets the zooming of the sprite. It resets any defined stretch values.

Parameters:
zoom The new zoom of the sprite. 1 is normal size, cannot be smaller than 0.

f32 wsp::Sprite::GetZoom (  )  const

Gets the zooming of the sprite. If StretchWidth is not the same as StretchHeight, it returns 0.

Returns:
The current zoom of the sprite. 1 is normal size.

void wsp::Sprite::SetStretchWidth ( f32  stretchWidth  ) 

Sets the width stretch of the sprite.

Parameters:
stretchWidth Stretches the width of the sprite by this value. 1 is normal size, cannot be smaller than 0.

void wsp::Sprite::SetStretchHeight ( f32  stretchHeight  ) 

Sets the height stretch of the sprite.

Parameters:
stretchHeight Stretches the height of the sprite by this value. 1 is normal size, cannot be smaller than 0.

f32 wsp::Sprite::GetStretchWidth (  )  const

Gets the width stretch of the sprite. Is equal to zoom value if zoom was set.

Returns:
The current width stretch of the sprite. 1 is normal size.

f32 wsp::Sprite::GetStretchHeight (  )  const

Gets the height stretch of the sprite. Is equal to zoom vallue if zoom was set.

Returns:
The current height stretch of the sprite. 1 is normal size.

void wsp::Sprite::SetTransparency ( u8  alpha  ) 

Sets the transparency of the sprite.

Parameters:
alpha Sets the transparency. Has a range from 0x00 (invisible) to 0xFF (fully visible)

u8 wsp::Sprite::GetTransparency (  )  const

Gets the transparency of the sprite.

Returns:
The current transparency of the sprite. Has a range from 0x00 (invisible) to 0xFF (fully visible)

void wsp::Sprite::DefineCollisionRectangle ( f32  x,
f32  y,
f32  width,
f32  height 
)

Defines a collision rectangle. On startup it's the same as Image width and height.

Parameters:
x Offset from the upper left corners position of the sprite.
y Offset from the upper left corners position of the sprite.
width The width of the collision rectangle.
height The height of the collision rectangle.

const Rectangle* wsp::Sprite::GetCollisionRectangle (  )  const

Gets the current collision rectangle.

Returns:
A pointer to the rectangle.

bool wsp::Sprite::CollidesWith ( const Rectangle rect,
f32  x = 0,
f32  y = 0 
) const

Checks if another rectangle collides with this sprite.

Parameters:
rect The rectangle to check.
x The position of the rectangle, since x in rectangle is only an offset.
y The position of the rectangle, since y in rectangle is only an offset.
Returns:
true if it is colliding, false if not.

bool wsp::Sprite::CollidesWith ( const Sprite sprite,
bool  complete = false 
) const

Checks if another sprite collides with this sprite.

Parameters:
sprite The sprite to check.
complete Set this to true, if you also want to use zoom and rotation with the collision detecting.
Returns:
true if it is colliding, false if not.

bool wsp::Sprite::CollidesWith ( const TiledLayer tiledlayer  )  const

Checks if the sprite does cross a tile on the tiledlayer which number is not 0.

Parameters:
tiledlayer the tiledlayer to check.
Returns:
true if it is colliding, false if not.

u32 wsp::Sprite::GetFrame (  )  const

Gets the current frame of the sprite.

Returns:
The frame this sprite is at.
See also:
Sprite - Animation Sequences

u32 wsp::Sprite::GetFrameSequencePos (  )  const

Gets the current position of the sequence. Equals to GetFrame() if sequence was not changed.

Returns:
The current position of the sequence.
See also:
Sprite - Animation Sequences

u32 wsp::Sprite::GetFrameSequenceLength (  )  const

Gets how long the current frame sequence is. Same as GetRawFrameCount() if no frame sequence speficied.

See also:
Sprite - Animation Sequences

u32 wsp::Sprite::GetRawFrameCount (  )  const

Gets how many frames there are at all.

See also:
Sprite - Animation Sequences

void wsp::Sprite::SetFrame ( u32  sequenceIndex  ) 

Sets the current frame to a frame at the sequence.

Parameters:
sequenceIndex The index in the current frame sequence.
See also:
Sprite - Animation Sequences

void wsp::Sprite::NextFrame (  ) 

Sets the current frame to the next frame in the sequence. Goes back to the first member if no frames left in the sequence.

See also:
Sprite - Animation Sequences

void wsp::Sprite::PrevFrame (  ) 

Sets the current frame to the previous frame in the sequence. Goes to the last member if the current frame is 0.

See also:
Sprite - Animation Sequences

void wsp::Sprite::SetFrameSequence ( u32 *  sequence,
u32  length 
)

Sets the current frame sequence.

Parameters:
sequence An array with data for each sequence. Each member cannot be bigger than the maximum amount of frames.
length The length of the sequence. Gets length amount of data.
See also:
Sprite - Animation Sequences


The documentation for this class was generated from the following file:

Generated on Sun Jun 29 14:29:27 2008 for libwiisprite by  doxygen 1.5.5