Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

Q3CanvasSprite Class

TheQ3CanvasSprite class provides an animated canvas item on aQ3Canvas.More...

Header:#include <Q3CanvasSprite>
Inherits:Q3CanvasItem

Public Types

enumFrameAnimationType { Cycle, Oscillate }

Public Functions

Q3CanvasSprite(Q3CanvasPixmapArray * a, Q3Canvas * canvas)
virtual~Q3CanvasSprite()
intbottomEdge() const
intbottomEdge(int ny) const
intframe() const
intframeCount() const
intheight() const
Q3CanvasPixmap *image() const
Q3CanvasPixmap *image(int f) const
virtual Q3CanvasPixmap *imageAdvanced() const
intleftEdge() const
intleftEdge(int nx) const
voidmove(double x, double y)
virtual voidmove(double nx, double ny, int nf)
intrightEdge() const
intrightEdge(int nx) const
voidsetFrame(int f)
virtual voidsetFrameAnimation(FrameAnimationType type = Cycle, int step = 1, int state = 0)
voidsetSequence(Q3CanvasPixmapArray * a)
inttopEdge() const
inttopEdge(int ny) const
intwidth() const

Reimplemented Public Functions

virtual voidadvance(int phase)
virtual QRectboundingRect() const
virtual boolcollidesWith(const Q3CanvasItem * i) const
virtual voiddraw(QPainter & painter)
virtual intrtti() const

Additional Inherited Members

Detailed Description

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.

Member Type Documentation

enum Q3CanvasSprite::FrameAnimationType

This enum is used to identify the different types of frame animation offered byQ3CanvasSprite.

ConstantValueDescription
Q3CanvasSprite::Cycle0at each advance the frame number will be incremented by 1 (modulo the frame count).
Q3CanvasSprite::Oscillate1at 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

Q3CanvasSprite::Q3CanvasSprite(Q3CanvasPixmapArray * a,Q3Canvas * canvas)

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

int Q3CanvasSprite::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 alsoleftEdge(),rightEdge(), andtopEdge().

int Q3CanvasSprite::bottomEdge(int ny) const

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

Reimplemented 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) const

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

int Q3CanvasSprite::frame() const

Returns the index of the current animation frame in theQ3CanvasSprite'sQ3CanvasPixmapArray.

See alsosetFrame() andmove().

int Q3CanvasSprite::frameCount() const

Returns the number of frames in theQ3CanvasSprite'sQ3CanvasPixmapArray.

int Q3CanvasSprite::height() const

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

See alsoframe().

Q3CanvasPixmap * Q3CanvasSprite::image() const

Returns the current frame's image.

See alsoframe() andsetFrame().

Q3CanvasPixmap * Q3CanvasSprite::image(int f) const

This is an overloaded function.

Returns the image for framef. Does not do any bounds checking onf.

[virtual]Q3CanvasPixmap * Q3CanvasSprite::imageAdvanced() const

Returns the image the spritewill have after advance(1) is called. By default this is the same asimage().

int Q3CanvasSprite::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 alsorightEdge(),bottomEdge(), andtopEdge().

int Q3CanvasSprite::leftEdge(int nx) const

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

void Q3CanvasSprite::move(double x,double y)

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.

int Q3CanvasSprite::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 alsoleftEdge(),bottomEdge(), andtopEdge().

int Q3CanvasSprite::rightEdge(int nx) const

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

Reimplemented fromQ3CanvasItem::rtti().

Returns 1 (Q3CanvasItem::Rtti_Sprite).

See alsoQ3CanvasItem::rtti().

void Q3CanvasSprite::setFrame(int f)

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.

See alsoframe() andmove().

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

void Q3CanvasSprite::setSequence(Q3CanvasPixmapArray * a)

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.

int Q3CanvasSprite::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 alsoleftEdge(),rightEdge(), andbottomEdge().

int Q3CanvasSprite::topEdge(int ny) const

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

int Q3CanvasSprite::width() const

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.


[8]ページ先頭

©2009-2025 Movatter.jp