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>
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) |
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!
| Sprite::Sprite | ( | SDL_Surface * | surf, | |
| double | zoom = 1., |
|||
| double | angle = 0. | |||
| ) |
Construct a Sprite from an existing SDL surface.
| 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.
| filename | The filename to take the picture from. | |
| zoom | Zoom value to apply. | |
| angle | Rotate picture, range: [0 - 360]. |
| void Sprite::anim | ( | int | delay, | |
| bool | loop_forever = true | |||
| ) |
Show all the frames successively, from the first to the last.
| 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. |
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.
| 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.
| 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.
| frame | The frame to show. |
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.
| level | Transparency level, between 0 (opaque) to 255 (completely transparent). |
| 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.
| nb_frame_width | The number of images in a row. | |
| nb_frame_height | The number of images in a column. |
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.
| 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. |
| 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, ...
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.
1.6.3