QCanvasSprite(3qt)

๐Ÿ“ฆ version 3.3.8b, in fedora 43, fedora 44

๐Ÿ’– QCanvasSprite ๐Ÿ’– โ€” from the 3qt manual, bestie

okay so picture this: it's the 3qt era, Trolltech is out here doing the most, and there's this whole class called QCanvasSprite that is lowkey the moment. let's get into it โœจ


๐ŸŒธ NAME ๐ŸŒธ

QCanvasSprite โ€” an animated canvas item on a QCanvas. yes, animated. yes, canvas. we love a glow-up.


๐ŸŽ€ SYNOPSIS ๐ŸŽ€

#include <qcanvas.h>

Inherits QCanvasItem. it's giving family tree, it's giving legacy ๐Ÿซถ

โœจ Public Members โœจ

QCanvasSprite ( QCanvasPixmapArray * a, QCanvas * canvas )
void setSequence ( QCanvasPixmapArray * a )
virtual ~QCanvasSprite ()
virtual void move ( double nx, double ny, int nf )
void setFrame ( int f )
enum FrameAnimationType { Cycle, Oscillate }
virtual void setFrameAnimation ( FrameAnimationType type = Cycle, int
    step = 1, int state = 0 )
int frame () const
int frameCount () const
virtual int rtti () const
virtual QRect boundingRect () const
int width () const
int height () const
int leftEdge () const
int topEdge () const
int rightEdge () const
int bottomEdge () const
int leftEdge ( int nx ) const
int topEdge ( int ny ) const
int rightEdge ( int nx ) const
int bottomEdge ( int ny ) const
QCanvasPixmap * image () const
virtual QCanvasPixmap * imageAdvanced () const
QCanvasPixmap * image ( int f ) const
virtual void advance ( int phase )
virtual void draw ( QPainter & painter )

look at all those methods. she's got range ๐Ÿ’…


๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

The QCanvasSprite class provides an animated canvas item on a QCanvas. periodt.

So a canvas sprite is an object that can hold any number of images โ€” we call those frames โ€” and only one of them is the current one, aka the one actually being displayed, at any given moment. the images can be handed over in the constructor, or you can set them / change them later with setSequence(). and if you subclass QCanvasSprite? you can swap which frame is showing on a schedule, like whenever QCanvasItem::advance(1) gets called โ€” and boom, that's your animation effect, bestie. main character energy fr fr.

The current frame can be set with setFrame() or with move(). how many frames do you even have? that's frameCount(). and the bounding rectangle of the current frame comes back from boundingRect(). iconic.

The current frame's image? grab it with image(). and use imageAdvanced() if you want to peek at the image for the frame that'll show up after advance(1) gets called โ€” it's giving clairvoyant, it's giving foresight ๐Ÿ”ฎ

Oh and there's an image() overload where you pass an integer index, and it hands you that particular image out of the whole list of frames. yes ma'am, index access.

Use width() and height() to get the dimensions of the current frame.

Use leftEdge() and rightEdge() to get the current frame's left-hand and right-hand x-coordinates respectively. Use bottomEdge() and topEdge() for the current frame's bottom and top y-coordinates respectively. and guess what โ€” these functions have an overload that takes an integer frame number so you can grab the coordinates of a specific frame. versatile queen ๐Ÿ‘‘

QCanvasSprite draws very quickly, at the expense of memory. trade-offs, we've all been there ๐Ÿ˜ญ

The current frame's image can be drawn on a painter with draw().

And like any other canvas item, canvas sprites can be moved with move() โ€” which sets the x and y coordinates and the frame number โ€” plus with QCanvasItem::move() and QCanvasItem::moveBy(), or by setting coordinates with QCanvasItem::setX(), QCanvasItem::setY() and QCanvasItem::setZ(). so many doors, all of them open ๐Ÿšชโœจ

See also Graphics Classes and Image Processing Classes.

๐Ÿงš Member Type Documentation ๐Ÿงš

QCanvasSprite::FrameAnimationType

This enum is used to identify the different types of frame animation offered by QCanvasSprite. two flavors, pick your fighter:

  • QCanvasSprite::Cycle โ€” at each advance the frame number will be incremented by 1 (modulo the frame count).
  • QCanvasSprite::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.

๐Ÿ’œ MEMBER FUNCTION DOCUMENTATION ๐Ÿ’œ

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. brand new baby sprite, fresh out the box ๐Ÿผ

QCanvasSprite::~QCanvasSprite () [virtual]

Destroys the sprite and removes it from the canvas. Does not delete the images. ok so important: she leaves, but she does NOT take the pictures with her. noted ๐Ÿ“

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.

See also QCanvasItem::advance() and setVelocity().

Example: canvas/canvas.cpp.

Reimplemented from QCanvasItem.

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.)

See also leftEdge(), rightEdge(), and topEdge().

int QCanvasSprite::bottomEdge ( int ny ) const

This is an overloaded member function, provided for convenience. It behaves essentially like the above 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-position ny.

See also leftEdge(), rightEdge(), and topEdge().

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). so crop your art properly, bestie, or this math goes sideways ๐Ÿ™ˆ

Reimplemented from QCanvasItem.

void QCanvasSprite::draw ( QPainter & painter ) [virtual]

Draws the current frame's image at the sprite's current position on painter painter. go little sprite, go ๐ŸŽจ

Reimplemented from QCanvasItem.

int QCanvasSprite::frame () const

Returns the index of the current animation frame in the QCanvasSprite's QCanvasPixmapArray.

See also setFrame() and move().

int QCanvasSprite::frameCount () const

Returns the number of frames in the QCanvasSprite's QCanvasPixmapArray. count 'em up ๐Ÿ”ข

int QCanvasSprite::height () const

The height of the sprite for the current frame's image.

See also frame().

QCanvasPixmap * QCanvasSprite::image () const

Returns the current frame's image.

See also frame() and setFrame().

QCanvasPixmap * QCanvasSprite::image ( int f ) const

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Returns the image for frame f. Does not do any bounds checking on f. so likeโ€ฆ be normal about f, okay? she's trusting you ๐Ÿซถ

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().

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.)

See also rightEdge(), bottomEdge(), and topEdge().

int QCanvasSprite::leftEdge ( int nx ) const

This is an overloaded member function, provided for convenience. It behaves essentially like the above 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-position nx.

See also rightEdge(), bottomEdge(), and topEdge().

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. so out-of-range frames just get politely declined, no drama ๐Ÿ’…

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.)

See also leftEdge(), bottomEdge(), and topEdge().

int QCanvasSprite::rightEdge ( int nx ) const

This is an overloaded member function, provided for convenience. It behaves essentially like the above 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-position nx.

See also leftEdge(), bottomEdge(), and topEdge().

int QCanvasSprite::rtti () const [virtual]

Returns 1 (QCanvasItem::Rtti_Sprite). that's the ID, bestie, remember it ๐Ÿ“‡

See also QCanvasItem::rtti().

Example: canvas/canvas.cpp.

Reimplemented from 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.

See also frame() and move().

void QCanvasSprite::setFrameAnimation ( FrameAnimationType type = Cycle, int step = 1, int state = 0 ) [virtual]

Sets the animation characteristics for the sprite. the vibe-setter, basically โœจ

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. hands off, it's private business ๐Ÿ™ˆ

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. she adapts, she survives ๐Ÿฆ‹

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.)

See also leftEdge(), rightEdge(), and bottomEdge().

int QCanvasSprite::topEdge ( int ny ) const

This is an overloaded member function, provided for convenience. It behaves essentially like the above 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-position ny.

See also leftEdge(), rightEdge(), and bottomEdge().

int QCanvasSprite::width () const

The width of the sprite for the current frame's image.

See also frame().


๐ŸŒˆ SEE ALSO ๐ŸŒˆ

go read more, you know you want to ๐Ÿ‘‘


Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the license file included in the distribution for a complete license statement.


๐Ÿ“ AUTHOR ๐Ÿ“

Generated automatically from the source code. (yes, a robot wrote this, and it ate, no cap ๐Ÿค–โœจ)


๐Ÿ’€ BUGS ๐Ÿ’€

If you find a bug in Qt, please report it as described in http://doc.trolltech.com/bughowto.html. Good bug reports help us to help you. Thank you. genuinely, thank you, bug reports are a love language ๐Ÿซถ

The definitive Qt documentation is provided in HTML format; it is located at $QTDIR/doc/html and can be read using Qt Assistant or with a web browser. This man page is provided as a convenience for those users who prefer man pages, although this format is not officially supported by Trolltech.

If you find errors in this manual page, please report them to qt-bugs@trolltech.com. Please include the name of the manual page (qcanvassprite.3qt) and the Qt version (3.3.8). don't forget those two things or the report goes nowhere bestie ๐Ÿ˜ญ


okay that's the whole page!! this one came from Trolltech AS, dated 2 February 2007, and it's the QCanvasSprite(3qt) man page from the Qt 3.3.8 era. mwah, go animate something iconic ๐Ÿ’–๐Ÿ’…โœจ

๐Ÿ“ฆ where this page comes from