
We bake cookies in your browser for a better experience. Using this site means that you consent.Read More
TheQ3CanvasSprite class provides an animated canvas item on aQ3Canvas.More...
| Header: | #include <Q3CanvasSprite> |
| Inherits: | Q3CanvasItem |
| enum | FrameAnimationType { Cycle, Oscillate } |
| Q3CanvasSprite(Q3CanvasPixmapArray * a, Q3Canvas * canvas) | |
| virtual | ~Q3CanvasSprite() |
| int | bottomEdge() const |
| int | bottomEdge(int ny) const |
| int | frame() const |
| int | frameCount() const |
| int | height() const |
| Q3CanvasPixmap * | image() const |
| Q3CanvasPixmap * | image(int f) const |
| virtual Q3CanvasPixmap * | imageAdvanced() const |
| int | leftEdge() const |
| int | leftEdge(int nx) const |
| void | move(double x, double y) |
| virtual void | move(double nx, double ny, int nf) |
| int | rightEdge() const |
| int | rightEdge(int nx) const |
| void | setFrame(int f) |
| virtual void | setFrameAnimation(FrameAnimationType type = Cycle, int step = 1, int state = 0) |
| void | setSequence(Q3CanvasPixmapArray * a) |
| int | topEdge() const |
| int | topEdge(int ny) const |
| int | width() const |
| virtual void | advance(int phase) |
| virtual QRect | boundingRect() const |
| virtual bool | collidesWith(const Q3CanvasItem * i) const |
| virtual void | draw(QPainter & painter) |
| virtual int | rtti() const |
TheQ3CanvasSprite class provides an animated canvas item on aQ3Canvas.
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 withsetSequence(). If you subclassQ3CanvasSprite you can change the frame that is displayed periodically, e.g. wheneverQ3CanvasItem::advance(1) is called to create the effect of animation.
The current frame can be set withsetFrame() or withmove(). The number of frames available is given byframeCount(). The bounding rectangle of the current frame is returned byboundingRect().
The current frame's image can be retrieved withimage(); useimageAdvanced() to retrieve the image for the frame that will be shown after advance(1) is called. Use theimage() overload passing it an integer index to retrieve a particular image from the list of frames.
Usewidth() andheight() to retrieve the dimensions of the current frame.
UseleftEdge() andrightEdge() to retrieve the current frame's left-hand and right-hand x-coordinates respectively. UsebottomEdge() andtopEdge() 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.
Q3CanvasSprite draws very quickly, at the expense of memory.
The current frame's image can be drawn on a painter withdraw().
Like any other canvas item, canvas sprites can be moved withmove() which sets the x and y coordinates and the frame number, as well as withQ3CanvasItem::move() andQ3CanvasItem::moveBy(), or by setting coordinates withQ3CanvasItem::setX(),Q3CanvasItem::setY() andQ3CanvasItem::setZ().
See alsoQtCanvas andPorting to Graphics View.
This enum is used to identify the different types of frame animation offered byQ3CanvasSprite.
| Constant | Value | Description |
|---|---|---|
Q3CanvasSprite::Cycle | 0 | at each advance the frame number will be incremented by 1 (modulo the frame count). |
Q3CanvasSprite::Oscillate | 1 | 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. |
Constructs aQ3CanvasSprite which uses images from theQ3CanvasPixmapArraya.
The sprite in initially positioned at (0, 0) oncanvas, using frame 0.
[virtual]Q3CanvasSprite::~Q3CanvasSprite()Destroys the sprite and removes it from the canvas. Doesnot delete the images.
[virtual]void Q3CanvasSprite::advance(int phase)Reimplemented fromQ3CanvasItem::advance().
Extends the defaultQ3CanvasItem implementation to provide the functionality ofsetFrameAnimation().
Thephase is 0 or 1: seeQ3CanvasItem::advance() for details.
See alsoQ3CanvasItem::advance() andsetVelocity().
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.)
See alsoleftEdge(),rightEdge(), andtopEdge().
This is an overloaded function.
Returns what the y-coordinate of the top edge of the sprite would be if the sprite (actually its hotspot) were moved to y-positionny.
See alsoleftEdge(),rightEdge(), andtopEdge().
[virtual]QRect Q3CanvasSprite::boundingRect() constReimplemented fromQ3CanvasItem::boundingRect().
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).
[virtual]bool Q3CanvasSprite::collidesWith(constQ3CanvasItem * i) constReimplemented fromQ3CanvasItem::collidesWith().
[virtual]void Q3CanvasSprite::draw(QPainter & painter)Reimplemented fromQ3CanvasItem::draw().
Draws the current frame's image at the sprite's current position on painterpainter.
Returns the index of the current animation frame in theQ3CanvasSprite'sQ3CanvasPixmapArray.
Returns the number of frames in theQ3CanvasSprite'sQ3CanvasPixmapArray.
The height of the sprite for the current frame's image.
See alsoframe().
Returns the current frame's image.
See alsoframe() andsetFrame().
This is an overloaded function.
Returns the image for framef. Does not do any bounds checking onf.
[virtual]Q3CanvasPixmap * Q3CanvasSprite::imageAdvanced() constReturns the image the spritewill have after advance(1) is called. By default this is the same asimage().
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.)
See alsorightEdge(),bottomEdge(), andtopEdge().
This is an overloaded function.
Returns what the x-coordinate of the left edge of the sprite would be if the sprite (actually its hotspot) were moved to x-positionnx.
See alsorightEdge(),bottomEdge(), andtopEdge().
Moves the sprite to (x,y).
[virtual]void Q3CanvasSprite::move(double nx,double ny,int nf)Moves the sprite to (nx,ny) and sets the current frame tonf.nf will be ignored if it is larger thanframeCount() or smaller than 0.
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.)
See alsoleftEdge(),bottomEdge(), andtopEdge().
This is an overloaded function.
Returns what the x-coordinate of the right edge of the sprite would be if the sprite (actually its hotspot) were moved to x-positionnx.
See alsoleftEdge(),bottomEdge(), andtopEdge().
[virtual]int Q3CanvasSprite::rtti() constReimplemented fromQ3CanvasItem::rtti().
Returns 1 (Q3CanvasItem::Rtti_Sprite).
See alsoQ3CanvasItem::rtti().
Sets the animation frame used for displaying the sprite tof, an index into theQ3CanvasSprite'sQ3CanvasPixmapArray. The call will be ignored iff is larger thanframeCount() or smaller than 0.
[virtual]void Q3CanvasSprite::setFrameAnimation(FrameAnimationType type = Cycle,int step = 1,int state = 0)Sets the animation characteristics for the sprite.
Fortype ==Cycle, the frames will increase bystep at each advance, modulo theframeCount().
Fortype ==Oscillate, the frames will increase bystep at each advance, up to theframeCount(), then decrease bystep back to 0, repeating forever.
Thestate parameter is for internal use.
Set the array of images used for displaying the sprite to theQ3CanvasPixmapArraya.
If the currentframe() is larger than the number of images ina, the current frame will be reset to 0.
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.)
See alsoleftEdge(),rightEdge(), andbottomEdge().
This is an overloaded function.
Returns what the y-coordinate of the top edge of the sprite would be if the sprite (actually its hotspot) were moved to y-positionny.
See alsoleftEdge(),rightEdge(), andbottomEdge().
The width of the sprite for the current frame's image.
See alsoframe().
© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.