Eneboo - Documentación para desarrolladores
Tipos públicos | Métodos públicos | Atributos públicos estáticos | Amigas
Referencia de la Clase QCanvasSprite

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>

Diagrama de herencias de QCanvasSprite
QCanvasItem QCanvasItem Qt Qt Qt Qt

Lista de todos los miembros.

Tipos públicos

enum  FrameAnimationType { Cycle, Oscillate, Cycle, Oscillate }
enum  FrameAnimationType { Cycle, Oscillate, Cycle, Oscillate }

Métodos públicos

 QCanvasSprite (QCanvasPixmapArray *array, QCanvas *canvas)
void setSequence (QCanvasPixmapArray *seq)
virtual ~QCanvasSprite ()
void move (double x, double y)
virtual void move (double x, double y, int frame)
void setFrame (int)
virtual void setFrameAnimation (FrameAnimationType=Cycle, int step=1, int state=0)
int frame () const
int frameCount () const
int rtti () const
bool collidesWith (const QCanvasItem *) const
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
QCanvasPixmapimage () const
virtual QCanvasPixmapimageAdvanced () const
QCanvasPixmapimage (int f) const
virtual void advance (int stage)
void draw (QPainter &painter)
 QCanvasSprite (QCanvasPixmapArray *array, QCanvas *canvas)
void setSequence (QCanvasPixmapArray *seq)
virtual ~QCanvasSprite ()
void move (double x, double y)
virtual void move (double x, double y, int frame)
void setFrame (int)
virtual void setFrameAnimation (FrameAnimationType=Cycle, int step=1, int state=0)
int frame () const
int frameCount () const
int rtti () const
bool collidesWith (const QCanvasItem *) const
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
QCanvasPixmapimage () const
virtual QCanvasPixmapimageAdvanced () const
QCanvasPixmapimage (int f) const
virtual void advance (int stage)
void draw (QPainter &painter)

Atributos públicos estáticos

static int RTTI = Rtti_Sprite

Amigas

bool qt_testCollision (const QCanvasSprite *s1, const QCanvasSprite *s2)
bool qt_testCollision (const QCanvasSprite *s1, const QCanvasSprite *s2)

Descripción detallada

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


Documentación de las enumeraciones miembro de la clase

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.

Valores de enumeraciones:
Cycle 
Oscillate 
Cycle 
Oscillate 
Valores de enumeraciones:
Cycle 
Oscillate 
Cycle 
Oscillate 

Documentación del constructor y destructor

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]

Documentación de las funciones miembro

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.

Ver también:
QCanvasItem::advance() setVelocity()

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.

Ver también:
QCanvas::advance() setVelocity()

Reimplementado de QCanvasItem.

int QCanvasSprite::bottomEdge ( int  ny) const

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.

Ver también:
leftEdge() rightEdge() topEdge()
int QCanvasSprite::bottomEdge ( ) const
int QCanvasSprite::bottomEdge ( int  ny) 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.)

Ver también:
leftEdge() rightEdge() topEdge()
QRect QCanvasSprite::boundingRect ( ) const [virtual]

Returns the bounding rectangle in pixels that the canvas item covers.

Ver también:
boundingRectAdvanced()

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.

Ver también:
collisions()

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.

Atención:
When you reimplement this function, make sure that you leave the painter in the same state as you found it. For example, if you start by calling QPainter::translate(50, 50), end your code by calling QPainter::translate(-50, -50). Be also aware that the painter might already have some transformations set (i.e., don't call QPainter::resetXForm() when you're done).

Implementa QCanvasItem.

int QCanvasSprite::frame ( ) const [inline]

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

Ver también:
setFrame(), move()
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.

Ver también:
frame()
QCanvasPixmap * QCanvasSprite::image ( ) const [inline]

Returns the current frame's image.

Ver también:
frame(), setFrame()
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().

int QCanvasSprite::leftEdge ( int  nx) const

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.

Ver también:
rightEdge() bottomEdge() topEdge()
int QCanvasSprite::leftEdge ( ) const
int QCanvasSprite::leftEdge ( int  nx) 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.)

Ver también:
rightEdge() bottomEdge() 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.

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.

int QCanvasSprite::rightEdge ( int  nx) const

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.

Ver también:
leftEdge() bottomEdge() topEdge()
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.)

Ver también:
leftEdge() bottomEdge() topEdge()
int QCanvasSprite::rightEdge ( int  nx) const
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).

Ver también:
QCanvasItem::rtti()

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.

Ver también:
frame() move()
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)
int QCanvasSprite::topEdge ( int  ny) const

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.

Ver también:
leftEdge() rightEdge() bottomEdge()
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.)

Ver también:
leftEdge() rightEdge() bottomEdge()
int QCanvasSprite::topEdge ( int  ny) const
int QCanvasSprite::topEdge ( ) const
int QCanvasSprite::width ( ) const

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

Ver también:
frame()
int QCanvasSprite::width ( ) const

Documentación de las funciones relacionadas y clases amigas

bool qt_testCollision ( const QCanvasSprite s1,
const QCanvasSprite s2 
) [friend]
bool qt_testCollision ( const QCanvasSprite s1,
const QCanvasSprite s2 
) [friend]

Documentación de los datos miembro

static int QCanvasSprite::RTTI = Rtti_Sprite [static]

Reimplementado de QCanvasItem.


La documentación para esta clase fue generada a partir de los siguientes ficheros:
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'