Eneboo - Documentación para desarrolladores
|
The QCanvasSprite class provides an animated canvas item on a QCanvas.canvasA canvas sprite is an object which can contain any number of images (referred to as frames), only one of which is current, i.e. displayed, at any one time. The images can be passed in the constructor or set or changed later with setSequence(). If you subclass QCanvasSprite you can change the frame that is displayed periodically, e.g. whenever QCanvasItem::advance(1) is called to create the effect of animation. Más...
#include <qcanvas.h>
The QCanvasSprite class provides an animated canvas item on a QCanvas.
canvas
A canvas sprite is an object which can contain any number of images (referred to as frames), only one of which is current, i.e. displayed, at any one time. The images can be passed in the constructor or set or changed later with setSequence(). If you subclass QCanvasSprite you can change the frame that is displayed periodically, e.g. whenever QCanvasItem::advance(1) is called to create the effect of animation.
The current frame can be set with setFrame() or with move(). The number of frames available is given by frameCount(). The bounding rectangle of the current frame is returned by boundingRect().
The current frame's image can be retrieved with image(); use imageAdvanced() to retrieve the image for the frame that will be shown after advance(1) is called. Use the image() overload passing it an integer index to retrieve a particular image from the list of frames.
Use width() and height() to retrieve the dimensions of the current frame.
Use leftEdge() and rightEdge() to retrieve the current frame's left-hand and right-hand x-coordinates respectively. Use bottomEdge() and topEdge() to retrieve the current frame's bottom and top y-coordinates respectively. These functions have an overload which will accept an integer frame number to retrieve the coordinates of a particular frame.
QCanvasSprite draws very quickly, at the expense of memory.
The current frame's image can be drawn on a painter with draw().
Like any other canvas item, canvas sprites can be moved with move() which sets the x and y coordinates and the frame number, as well as with QCanvasItem::move() and QCanvasItem::moveBy(), or by setting coordinates with QCanvasItem::setX(), QCanvasItem::setY() and QCanvasItem::setZ().
This enum is used to identify the different types of frame animation offered by QCanvasSprite.
Cycle at each advance the frame number will be incremented by 1 (modulo the frame count). Oscillate at each advance the frame number will be incremented by 1 up to the frame count then decremented to by 1 to 0, repeating this sequence forever.
QCanvasSprite::QCanvasSprite | ( | QCanvasPixmapArray * | a, |
QCanvas * | canvas | ||
) |
Constructs a QCanvasSprite which uses images from the QCanvasPixmapArray a.
The sprite in initially positioned at (0, 0) on canvas, using frame 0.
QCanvasSprite::~QCanvasSprite | ( | ) | [virtual] |
Destroys the sprite and removes it from the canvas. Does not delete the images.
QCanvasSprite::QCanvasSprite | ( | QCanvasPixmapArray * | array, |
QCanvas * | canvas | ||
) |
virtual QCanvasSprite::~QCanvasSprite | ( | ) | [virtual] |
void QCanvasSprite::advance | ( | int | phase | ) | [virtual] |
Extends the default QCanvasItem implementation to provide the functionality of setFrameAnimation().
The phase is 0 or 1: see QCanvasItem::advance() for details.
Reimplementado de QCanvasItem.
virtual void QCanvasSprite::advance | ( | int | phase | ) | [virtual] |
The default implementation moves the canvas item, if it is animated(), by the preset velocity if phase is 1, and does nothing if phase is 0.
Note that if you reimplement this function, the reimplementation must not change the canvas in any way, for example it must not add or remove items.
Reimplementado de QCanvasItem.
Esta es una función miembro sobrecargada que se suministra por conveniencia. Difiere de la anterior función solamente en los argumentos que acepta. Returns what the y-coordinate of the top edge of the sprite would be if the sprite (actually its hotspot) were moved to y-position ny.
int QCanvasSprite::bottomEdge | ( | ) | const |
int QCanvasSprite::bottomEdge | ( | ) | const |
Returns the y-coordinate of the current bottom edge of the sprite. (This may change as the sprite animates since different frames may have different bottom edges.)
QRect QCanvasSprite::boundingRect | ( | ) | const [virtual] |
Returns the bounding rectangle in pixels that the canvas item covers.
Implementa QCanvasItem.
QRect QCanvasSprite::boundingRect | ( | ) | const [virtual] |
Returns the bounding rectangle for the image in the sprite's current frame. This assumes that the images are tightly cropped (i.e. do not have transparent pixels all along a side).
Implementa QCanvasItem.
bool QCanvasSprite::collidesWith | ( | const QCanvasItem * | i | ) | const [virtual] |
Implementa QCanvasItem.
bool QCanvasSprite::collidesWith | ( | const QCanvasItem * | other | ) | const [virtual] |
Returns TRUE if the canvas item will collide with the other item after they have moved by their current velocities; otherwise returns FALSE.
Implementa QCanvasItem.
void QCanvasSprite::draw | ( | QPainter & | painter | ) | [virtual] |
Draws the current frame's image at the sprite's current position on painter painter.
Implementa QCanvasItem.
void QCanvasSprite::draw | ( | QPainter & | painter | ) | [virtual] |
This abstract virtual function draws the canvas item using painter.
Implementa QCanvasItem.
int QCanvasSprite::frame | ( | ) | const [inline] |
Returns the index of the current animation frame in the QCanvasSprite's QCanvasPixmapArray.
int QCanvasSprite::frame | ( | ) | const [inline] |
int QCanvasSprite::frameCount | ( | ) | const [inline] |
int QCanvasSprite::frameCount | ( | ) | const [inline] |
Returns the number of frames in the QCanvasSprite's QCanvasPixmapArray.
int QCanvasSprite::height | ( | ) | const |
int QCanvasSprite::height | ( | ) | const |
The height of the sprite for the current frame's image.
QCanvasPixmap * QCanvasSprite::image | ( | ) | const [inline] |
Returns the current frame's image.
QCanvasPixmap* QCanvasSprite::image | ( | int | f | ) | const [inline] |
QCanvasPixmap * QCanvasSprite::image | ( | int | f | ) | const [inline] |
Esta es una función miembro sobrecargada que se suministra por conveniencia. Difiere de la anterior función solamente en los argumentos que acepta. Returns the image for frame f. Does not do any bounds checking on f.
QCanvasPixmap* QCanvasSprite::image | ( | ) | const [inline] |
virtual QCanvasPixmap* QCanvasSprite::imageAdvanced | ( | ) | const [virtual] |
QCanvasPixmap * QCanvasSprite::imageAdvanced | ( | ) | const [virtual] |
Returns the image the sprite will have after advance(1) is called. By default this is the same as image().
Esta es una función miembro sobrecargada que se suministra por conveniencia. Difiere de la anterior función solamente en los argumentos que acepta. Returns what the x-coordinate of the left edge of the sprite would be if the sprite (actually its hotspot) were moved to x-position nx.
int QCanvasSprite::leftEdge | ( | ) | const |
int QCanvasSprite::leftEdge | ( | ) | const |
Returns the x-coordinate of the current left edge of the sprite. (This may change as the sprite animates since different frames may have different left edges.)
void QCanvasSprite::move | ( | double | nx, |
double | ny, | ||
int | nf | ||
) | [virtual] |
Set the position of the sprite to nx, ny and the current frame to nf. nf will be ignored if it is larger than frameCount() or smaller than 0.
void QCanvasSprite::move | ( | double | x, |
double | y | ||
) |
Moves the canvas item to the absolute position (x, y).
Reimplementado de QCanvasItem.
virtual void QCanvasSprite::move | ( | double | x, |
double | y, | ||
int | frame | ||
) | [virtual] |
void QCanvasSprite::move | ( | double | x, |
double | y | ||
) |
Reimplementado de QCanvasItem.
Esta es una función miembro sobrecargada que se suministra por conveniencia. Difiere de la anterior función solamente en los argumentos que acepta. Returns what the x-coordinate of the right edge of the sprite would be if the sprite (actually its hotspot) were moved to x-position nx.
int QCanvasSprite::rightEdge | ( | ) | const |
Returns the x-coordinate of the current right edge of the sprite. (This may change as the sprite animates since different frames may have different right edges.)
int QCanvasSprite::rightEdge | ( | ) | const |
int QCanvasSprite::rtti | ( | ) | const [virtual] |
Returns 0 (QCanvasItem::Rtti_Item).
Make your derived classes return their own values for rtti(), so that you can distinguish between objects returned by QCanvas::at(). You should use values greater than 1000 to allow for extensions to this class.
Overuse of this functionality can damage it's extensibility. For example, once you have identified a base class of a QCanvasItem found by QCanvas::at(), cast it to that type and call meaningful methods rather than acting upon the object based on its rtti value.
For example:
QCanvasItem* item; // Find an item, e.g. with QCanvasItem::collisions(). ... if (item->rtti() == MySprite::RTTI ) { MySprite* s = (MySprite*)item; if (s->isDamagable()) s->loseHitPoints(1000); if (s->isHot()) myself->loseHitPoints(1000); ... }
Reimplementado de QCanvasItem.
int QCanvasSprite::rtti | ( | ) | const [virtual] |
Returns 1 (QCanvasItem::Rtti_Sprite).
Reimplementado de QCanvasItem.
void QCanvasSprite::setFrame | ( | int | f | ) |
Sets the animation frame used for displaying the sprite to f, an index into the QCanvasSprite's QCanvasPixmapArray. The call will be ignored if f is larger than frameCount() or smaller than 0.
void QCanvasSprite::setFrame | ( | int | ) |
virtual void QCanvasSprite::setFrameAnimation | ( | FrameAnimationType | = Cycle , |
int | step = 1 , |
||
int | state = 0 |
||
) | [virtual] |
void QCanvasSprite::setFrameAnimation | ( | FrameAnimationType | type = Cycle , |
int | step = 1 , |
||
int | state = 0 |
||
) | [virtual] |
Sets the animation characteristics for the sprite.
For type == Cycle
, the frames will increase by step at each advance, modulo the frameCount().
For type == Oscillate
, the frames will increase by step at each advance, up to the frameCount(), then decrease by step back to 0, repeating forever.
The state parameter is for internal use.
void QCanvasSprite::setSequence | ( | QCanvasPixmapArray * | a | ) |
Set the array of images used for displaying the sprite to the QCanvasPixmapArray a.
If the current frame() is larger than the number of images in a, the current frame will be reset to 0.
void QCanvasSprite::setSequence | ( | QCanvasPixmapArray * | seq | ) |
Esta es una función miembro sobrecargada que se suministra por conveniencia. Difiere de la anterior función solamente en los argumentos que acepta. Returns what the y-coordinate of the top edge of the sprite would be if the sprite (actually its hotspot) were moved to y-position ny.
int QCanvasSprite::topEdge | ( | ) | const |
Returns the y-coordinate of the top edge of the sprite. (This may change as the sprite animates since different frames may have different top edges.)
int QCanvasSprite::topEdge | ( | ) | const |
int QCanvasSprite::width | ( | ) | const |
The width of the sprite for the current frame's image.
int QCanvasSprite::width | ( | ) | const |
bool qt_testCollision | ( | const QCanvasSprite * | s1, |
const QCanvasSprite * | s2 | ||
) | [friend] |
bool qt_testCollision | ( | const QCanvasSprite * | s1, |
const QCanvasSprite * | s2 | ||
) | [friend] |
static int QCanvasSprite::RTTI = Rtti_Sprite [static] |
Reimplementado de QCanvasItem.