# QwVirtualSprite Class Reference

A QwSpriteFieldGraphic which renders as a masked image. More...

`#include <QwSpriteField.h>`

Inherits QwSpriteFieldGraphic.

Inherited by QwPositionedSprite.

List of all member functions.

## Public Members

- QwVirtualSprite ()
- virtual ~QwVirtualSprite ()
- int width () const
- int height () const
- int colWidth () const
- int colHeight () const
- virtual QwSpritePixmap* image () const
- virtual int x () const
- virtual int y () const
- virtual bool at ( int x, int y ) const
- virtual bool at ( const QRect & rect ) const
- virtual bool at ( const QImage * image, const QRect & rect ) const
- virtual int rtti () const
- Pix neighbourhood () const
- Pix neighbourhood ( int nx, int ny ) const
- Pix neighbourhood ( int nx, int ny, QwSpritePixmap * ) const
- void next ( Pix & ) const
- void end ( Pix & p ) const
- QwSpriteFieldGraphic* at ( Pix p ) const
- bool exact ( Pix p ) const
- bool hitting ( QwSpriteFieldGraphic & ) const
- bool wouldHit ( QwSpriteFieldGraphic &, int x, int y, QwSpritePixmap * ) const

## Static Public Members

- void setPixelCollisionPrecision ( int downshifts )
- int world_to_col ( int i )
- int col_to_world ( int i )

## Protected Members

- virtual void makeVisible ( bool yes )
- virtual void draw ( QPainter & )
- void addToChunks ()
- void removeFromChunks ()
- int absX () const
- int absY () const
- int absX2 () const
- int absY2 () const
- int absColX () const
- int absColY () const
- int absColX2 () const
- int absColY2 () const
- int absX ( int nx ) const
- int absY ( int ny ) const
- int absX2 ( int nx ) const
- int absY2 ( int ny ) const

## Detailed Description

A QwSpriteFieldGraphic which renders as a masked image.

QwVirtualSprites are most of the implementation of sprites, except they do not define the x(), y(), z() and image() methods. This allows for user-defined coordinates systems and animation methods.

See also: QwSprite.

## Member Function Documentation

### QwVirtualSprite::QwVirtualSprite ()

Construct a QwVirtualSprite. Derived classes should call addToChunks() in their constructor once x(), y(), and image() are valid.

### QwVirtualSprite::~QwVirtualSprite () `[virtual]`

Destruct the QwVirtualSprite. Derived classes must remove the sprite from any chunks, as this destructor cannot call the virtual methods required to do so.

### int QwVirtualSprite::absColX () const `[protected]`

The left edge, in collision-detection coordinates.

See also: QwVirtualSprite::setPixelCollisionPrecision(int).

### int QwVirtualSprite::absColX2 () const `[protected]`

The right edge, in collision-detection coordinates.

See also: QwVirtualSprite::setPixelCollisionPrecision(int).

### int QwVirtualSprite::absColY () const `[protected]`

The top edge, in collision-detection coordinates.

See also: QwVirtualSprite::setPixelCollisionPrecision(int).

### int QwVirtualSprite::absColY2 () const `[protected]`

The bottom edge, in collision-detection coordinates.

See also: QwVirtualSprite::setPixelCollisionPrecision(int).

### int QwVirtualSprite::absX () const `[protected]`

The absolute horizontal position of the QwVirtualSprite. This is the pixel position of the left edge of the image, as it takes into account the hotspot.

### int QwVirtualSprite::absX ( int nx ) const `[protected]`

The absolute horizontal position of the QwVirtualSprite, if it was moved to nx.

### int QwVirtualSprite::absX2 () const `[protected]`

The right edge of the sprite image.

See also: absX().

### int QwVirtualSprite::absX2 ( int nx ) const `[protected]`

The right edge of the sprite image, if it was moved to nx.

See also: absX().

### int QwVirtualSprite::absY () const `[protected]`

The absolute vertical position of the QwVirtualSprite. This is the pixel position of the top edge of the image, as it takes into account the hotspot.

### int QwVirtualSprite::absY ( int ny ) const `[protected]`

The absolute vertical position of the QwVirtualSprite, if it was moved to ny.

### int QwVirtualSprite::absY2 () const `[protected]`

The bottom edge of the sprite image.

See also: absY().

### int QwVirtualSprite::absY2 ( int ny ) const `[protected]`

The bottom edge of the sprite image, if it was moved to ny.

See also: absY().

### void QwVirtualSprite::addToChunks () `[protected]`

Add the sprite to the chunks in its QwSpriteField which it overlaps.

This must be called as the values of x(), y(), and image() change such that the QwVirtualSprite is removed from chunks it is in, the values of x(), y(), and image() change, then it is added back into the then covered chunks in the QwSpriteField.

The QwPositionedSprite and derived classes deals with this automatically, as must other derived classes of QwVirtualSprite.

### QwSpriteFieldGraphic* QwVirtualSprite::at ( Pix p ) const

Returns the QwSpriteFieldGraphic at the given traversal point.

See also: neighbourhood(int,int,QwSpritePixmap*).

### bool QwVirtualSprite::at ( const QImage * yourimage, const QRect & yourarea ) const `[virtual]`

Used by the methods associated with QwSpriteField::topAt(int x, int y) to test for an exact hit.

See also: neighbourhood(int,int,QwSpritePixmap*).

### bool QwVirtualSprite::at ( const QRect & rect ) const `[virtual]`

Used by the methods associated with QwSpriteField::topAt(int x, int y) to test for a close hit.

See also: neighbourhood(int,int,QwSpritePixmap*).

### bool QwVirtualSprite::at ( int px, int py ) const `[virtual]`

(override)

Tests if the given pixel touches the sprite. This uses pixel-accurate detection, using the collision mask of the sprites current image (which is by default the image mask). This test is useful for example to test when the user clicks a point with they mouse. Note however, that QwSpriteField::topAt(int x, int y) and associated methods give a more efficient and flexible technique for this purpose.

### int QwVirtualSprite::colHeight () const

The height of the sprite in collision-detection coordinates.

### int QwVirtualSprite::colWidth () const

The width of the sprite in collision-detection coordinates.

### int QwVirtualSprite::col_to_world ( int i ) `[static]`

Convert a coordinate from collision to world coordinates.

See also: setPixelCollisionPrecision(int) and QwSpriteField::setPositionPrecision.

### void QwVirtualSprite::draw ( QPainter & painter ) `[virtual protected]`

(override)

Draws the current image of the sprite at its current position, as given by image() and x(), y().

### void QwVirtualSprite::end ( Pix & p ) const

Terminate a traversal early.

See also: neighbourhood(int,int,QwSpritePixmap*) and QwSpriteField::end(Pix&).

### bool QwVirtualSprite::exact ( Pix p ) const

See also: neighbourhood(int,int,QwSpritePixmap*) and const.

### int QwVirtualSprite::height () const

The height of the sprite, in its current image.

### bool QwVirtualSprite::hitting ( QwSpriteFieldGraphic & other ) const

Test if this sprite is touching the given QwSpriteFieldGraphic. This is a convenient packaging of neighbourhood() and related methods.

### QwSpritePixmap* QwVirtualSprite::image () const `[virtual]`

This abstract method should return the pixmap to be drawn for the sprite.

### void QwVirtualSprite::makeVisible ( bool yes ) `[virtual protected]`

Adds/removes the sprite from the QwSpriteField chunks it covers, as required by QwSpriteFieldGraphic. This, addToChunks, and the removeFromChunks method may be moved up to QwSpriteFieldGraphic. Either way, this or the other two would have to be virtual.

### Pix QwVirtualSprite::neighbourhood () const

Creates an iterator which traverses the QwSpriteFieldGraphic objects which collide with this sprite at its current position.

See also: neighbourhood(int,int,QwSpritePixmap*).

### Pix QwVirtualSprite::neighbourhood ( int nx, int ny ) const

Creates an iterator which traverses the QwSpriteFieldGraphic objects which would collide with this sprite if it was moved to the given position (yet kept its current image).

See also: neighbourhood(int,int,QwSpritePixmap*).

### Pix QwVirtualSprite::neighbourhood ( int nx, int ny, QwSpritePixmap * img ) const

Creates an iterator which can traverse the area which the QwVirtualSprite would cover if it had the given position and image. This `would cover' concept is useful as it allows you to check for a collision before moving the sprite.

### void QwVirtualSprite::next ( Pix & p ) const

Traverse to the next QwSpriteFieldGraphic in a collision list.

See also: neighbourhood(int,int,QwSpritePixmap*).

### void QwVirtualSprite::removeFromChunks () `[protected]`

Remove the sprite from the chunks in its QwSpriteField which it overlaps.

See also: addToChunks().

### int QwVirtualSprite::rtti () const `[virtual]`

Returns 1.

See also: QwSpriteFieldGraphic::rtti().

### void QwVirtualSprite::setPixelCollisionPrecision ( int downshifts ) `[static]`

Using this method, the resolution of the collision mask can be different to the resolution of the pixel coordinates of the sprites. One possible use for this is to have differently scaled graphics being used by different players in a multiplayer distributed game, yet for the collision detection to be identical for each player.

See also: QwSpritePixmapSequence::readCollisionMasks(...).

### int QwVirtualSprite::width () const

The width of the sprite, in its current image.

### int QwVirtualSprite::world_to_col ( int i ) `[static]`

Convert a coordinate from world to collision coordinates.

See also: setPixelCollisionPrecision(int) and QwSpriteField::setPositionPrecision.

### bool QwVirtualSprite::wouldHit ( QwSpriteFieldGraphic & other, int x, int y, QwSpritePixmap * img ) const

Test if this sprite would (exactly) touch the given QwSpriteFieldGraphic. This is a convenient packaging of neighbourhood() and related methods.

### int QwVirtualSprite::x () const `[virtual]`

This abstract method should return the horizontal location, measured from the left edge of the QwSpriteField, at which to draw the pixmap of the sprite. Note that the hotspot of the pixmap will be taken into account.

### int QwVirtualSprite::y () const `[virtual]`

This abstract method should return the vertical location, measured from the top edge of the QwSpriteField, at which to draw the pixmap of the sprite. Note that the hotspot of the pixmap will be taken into account.

This file is copyright © 1995-97 Warwick Allison.

It was generated from the following files:

- QwSpriteField.h
- QwSpriteField-double.cpp
- QwSpriteField-int.cpp
- QwSpriteField-mobdouble.cpp
- QwSpriteField-mobint.cpp
- QwSpriteField-template.cpp
- QwSpriteField.cpp