Sprite Class Reference
[C++ Wrapper for SDL]

Enhancement of Surface, give life to object.Have the same behavior of Surface, but have some more features: * can be animated * can be moved from one position to another * can show a part of a larger picture (useful when a picture consists of several 'state'). More...

#include <Sprite.hh>

Inheritance diagram for Sprite:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 Sprite ()
 Constructor for a empty sprite.
 Sprite (SDL_Surface *surf, double zoom=1., double angle=0.)
 Construct a Sprite from an existing SDL surface.
 Sprite (const std::string filename, double zoom=1., double angle=0.)
 Construct a Sprite from a picture file.
void splitNbFrame (int nb_frame_width, int nb_frame_height)
 Split the current surface into 'multiple' surfaces.
void splitSizeFrame (int size_frame_width, int size_frame_height)
 Split the current surface into 'multiple' surfaces.
void move (const Point &to, double velocity)
 Move the sprite from the current position to the specified position, at a specified speed.
void move (int to_x, int to_y, double velocity)
 Move the sprite from the current position to the specified position, at a specified speed.
void stopMove ()
 Stop move, net.
bool isMoving ()
void anim (int delay, bool loop_forever=true)
 Show all the frames successively, from the first to the last.
void stopAnim ()
 Stop animation, created previously by anim.
bool isAnimated ()
void setFrame (int frame)
 Show the specified frame.
void setTransparency (int level)
 Modify sprite transparency.
virtual void setZoom (double zoom)
virtual void update ()
 Method called each frame, to perfom user custom code.
virtual void blit (Surface &to)
virtual void blit (Surface &to, const Rect &to_rect, const Rect &from_rect)

Detailed Description

Enhancement of Surface, give life to object.

Have the same behavior of Surface, but have some more features: * can be animated * can be moved from one position to another * can show a part of a larger picture (useful when a picture consists of several 'state').

Here a simple example:

 Sprite s("general/foo.png");
 s.setPos(50, 100);      // same thing as Surface.
 s.setZ(3);              // idem.
 s.splitNbFrame(4, 1);   // 4 'frames' in the row.
 s.anim(250);            // show one of these frames every 250ms.
 s.move(800, 100, 30.);  // move the sprite
 win.getScreen().addChild(&s); // don't forget that!

Constructor & Destructor Documentation

Sprite::Sprite ( SDL_Surface *  surf,
double  zoom = 1.,
double  angle = 0. 
)

Construct a Sprite from an existing SDL surface.

Parameters:
surf The surface to 'swallow'.
zoom Zoom value to apply.
angle Rotate picture, range: [0 - 360].
Sprite::Sprite ( const std::string  filename,
double  zoom = 1.,
double  angle = 0. 
)

Construct a Sprite from a picture file.

Parameters:
filename The filename to take the picture from.
zoom Zoom value to apply.
angle Rotate picture, range: [0 - 360].

Member Function Documentation

void Sprite::anim ( int  delay,
bool  loop_forever = true 
)

Show all the frames successively, from the first to the last.

Parameters:
delay Wait this time before going to next frame (in ms).
loop_forever When arrived at the last frame, go to the first and continue.
Note:
Before using it, you have to split the Sprite into frames, with splitNbFrame or splitSizeFrame.

Referenced by sdlvisu::VisuPlayer::update(), and sdlvisu::Panel::update().

void Sprite::move ( int  to_x,
int  to_y,
double  velocity 
)

Move the sprite from the current position to the specified position, at a specified speed.

This create an animation.

Parameters:
to_x X coordinates to move to.
to_y T coordinates to move to.
velocity Speed at which this sprite will move (try value between 10. and 100.).

References move().

void Sprite::move ( const Point to,
double  velocity 
)

Move the sprite from the current position to the specified position, at a specified speed.

This create an animation.

Parameters:
to Position to move to.
velocity Speed at which this sprite will move (try value between 10. and 100.).

References Surface::getPos(), Surface::getRect(), Surface::getSize(), VirtualSurface::invalidate(), TPoint< T >::x, and TPoint< T >::y.

Referenced by move().

void Sprite::setFrame ( int  frame  ) 

Show the specified frame.

Parameters:
frame The frame to show.
Note:
Before using it, you have to split the Sprite into frames, with splitNbFrame or splitSizeFrame.
Not compatible with anim method.

Referenced by sdlvisu::InfoBar::addBlockDice(), sdlvisu::VisuPlayer::beginTurn(), sdlvisu::Map::drawPath(), sdlvisu::VisuPlayer::onEventAction(), sdlvisu::Panel::setHalf(), sdlvisu::Panel::setTurn(), sdlvisu::Panel::unsetTurnCursor(), sdlvisu::Panel::update(), and sdlvisu::VisuPlayer::updateStatus().

void Sprite::setTransparency ( int  level  ) 

Modify sprite transparency.

It modify the surface alpha channel with the specified level.

Parameters:
level Transparency level, between 0 (opaque) to 255 (completely transparent).
Note:
This function is in beta-test! Do not expect too much from it.
void Sprite::splitNbFrame ( int  nb_frame_width,
int  nb_frame_height 
)

Split the current surface into 'multiple' surfaces.

To be used when the input image have itself several images, each one having the same size, and you want to display only one at a time.

Parameters:
nb_frame_width The number of images in a row.
nb_frame_height The number of images in a column.
Note:
A picture must be loaded before.

Referenced by sdlvisu::Map::drawPath().

void Sprite::splitSizeFrame ( int  size_frame_width,
int  size_frame_height 
)

Split the current surface into 'multiple' surfaces.

To be used when the input image have itself several images, each one having the same size, and you want to display only one at a time.

Parameters:
size_frame_width The size of one 'sub' image in pixel on a row.
size_frame_height The size of one 'sub' image in pixel on a column.
Note:
A picture must be loaded before.
void Sprite::update (  )  [virtual]

Method called each frame, to perfom user custom code.

You should override it.

Since a parent is assigned to the surface (and this parent is itself attached by other means to the root screen), this method is called at each frame. It is not called if this surface or one of its parent is disabled. In this method you can do what you want with your object, like processing input, updating other programs attributes, changing surface property, ...

Note:
Don't forget to call update for the base class at the end of your function , otherwise strange things will happen.

Reimplemented from Surface.

Reimplemented in sdlvisu::GameButton, and sdlvisu::VisuPlayer.

References TPoint< T >::distance(), Surface::getRect(), Surface::getSize(), VirtualSurface::invalidate(), TPoint< T >::x, and TPoint< T >::y.


The documentation for this class was generated from the following files:
Generated on Mon Apr 5 21:17:46 2010 for Stechec/TBT by  doxygen 1.6.3