QwSpriteFieldGraphic Class Reference


An abstract graphic object on a QwSpriteField. More...

#include <QwSpriteField.h>

Inherited by QwPolygonalGraphic, QwTextSprite and QwVirtualSprite.

List of all member functions.

Public Members

Static Public Members

Protected Members


Detailed Description

An abstract graphic object on a QwSpriteField.

This class will primarily be of interest to those wanting to add graphic objects other than the sprite object already defined.

In most graphic rendering systems, graphic objects are considered to have a bounding rectangle, and redraw optimization is based on this simplification. This simplistic view is not used by QwSpriteField. A QwSpriteField considers itself to contain numerous graphic objects, each of which covers certain `chunks' in the QwSpriteField. For graphic objects with a rectangular bias, this has only a minor effect on redraw efficiency (although still a major effect on collision detection and other area indexing). But for other shapes, such as lines, the tighter area-bound made possible by chunks can provide improvements.

Whenever a QwSpriteFieldGraphic moves, it must add and remove itself from the chunks of the QwSpriteField upon which it moves. If the QwSpriteFieldGraphic is much smaller than the chunk size of the QwSpriteField, it will usually be in one, sometimes 2, and occasionally 3 or 4 chunks. If the QwSpriteFieldGraphic is larger than the chunk size of the QwSpriteField, it will span a number of chunks. Clearly there is a trade-off between tight bounds and excessive numbers of chunks a QwSpriteFieldGraphic will have to add and remove itself from.

Note that a QwSpriteFieldGraphic may be `on' a QwSpriteField even if it's coordinates place it far off the edge of the area of the QwSpriteField.


Member Function Documentation

QwSpriteFieldGraphic::QwSpriteFieldGraphic ()

Construct a QwSpriteFieldGraphic on the current spritefield.

See also: setCurrentSpriteField(QwSpriteField*) and setSpriteField(QwSpriteField*).

QwSpriteFieldGraphic::~QwSpriteFieldGraphic () [virtual]

Destruct a QwSpriteFieldGraphic. It is removed from its spritefield.

bool QwSpriteFieldGraphic::at ( const QImage *, const QRect & yourarea ) const [virtual]

QwSpriteFieldGraphic derivatives can give pixel-accuracy for collision detection by overriding this method. By default, it simply returns at(const QRect&) on the same area.

bool QwSpriteFieldGraphic::at ( const QRect & rect ) const [virtual]

TRUE if the graphic intersects with the given area. This need not be perfectly accurate.

bool QwSpriteFieldGraphic::at ( int x, int y ) const [virtual]

Should return TRUE if the graphic includes the given pixel position.

Reimplemented in QwTextSprite.

void QwSpriteFieldGraphic::draw ( QPainter & ) [virtual]

This abstract method should draw the the graphic on the given QPainter.

void QwSpriteFieldGraphic::hide ()

Alias for visible(FALSE).

void QwSpriteFieldGraphic::makeVisible ( bool ) [virtual protected]

The default implementation of makeVisible(bool) does nothing.

Note: derived classes should not be in any chunks if they are not visible, so during this method, they should remove themselves if they are becoming invisible, and add themselves if they are becoming visible.

int QwSpriteFieldGraphic::rtti () const [virtual]

Returns 0.

Although often frowned upon by purists, Run Time Type Identification is very useful in this case, as it allows a QwSpriteField to be an efficient indexed storage mechanism.

Make your derived classes return their own values for rtti(), and you can distinguish between objects returned by QwSpriteField::at(). You should use values greater than 1000 preferrably a large random number, to allow for extensions to this class.

However, it is important not to overuse this facility, as it damages extensibility. For example, once you have identified a base class of a QwSpriteFieldGraphic found by QwSpriteField::at(), cast it to that type and call meaningful methods rather than acting upon the object based on its rtti value.

For example:

    if (field.at(p)->rtti() == MySprite::rtti()) {
    MySprite* s = (MySprite*)field.at(p);
    if (s->isDamagable()) s->loseHitPoints(1000);
    if (s->isHot()) myself->loseHitPoints(1000);
    ...
    }

void QwSpriteFieldGraphic::setCurrentSpriteField ( QwSpriteField * pf ) [static]

QwSpriteFieldGraphics may be created on a `current' QwSpriteField, which must be set prior to any graphic creation. QwSpriteField objects set this, so the most recently created QwSpriteField will get new QwSpriteFieldGraphics.

This notion of `currency' makes the most common case easy to use - that of a single instance of QwSpriteField in the application - rather than having to pass around a pointer to a QwSpriteField.

void QwSpriteFieldGraphic::setSpriteField ( QwSpriteField * pf )

Set the QwSpriteField upon which the QwSpriteFieldGraphic is to be drawn. Initially this will be the current spritefield.

See also: setCurrentSpriteField(QwSpriteField*).

void QwSpriteFieldGraphic::show ()

Alias for visible(TRUE).

bool QwSpriteFieldGraphic::visible () const

Returns TRUE if the QwSpriteFieldGraphic is visible. This does not mean the QwSpriteFieldGraphic is currently in a view, merely that if a view was showing the area where the QwSpriteFieldGraphic is, and the graphic was not obscured by graphics at a higher z, it would be visible.

void QwSpriteFieldGraphic::visible ( bool yes )

Calls makeVisible(bool) if necessary to set the visibility of the QwSpriteFieldGraphic to the given state.

int QwSpriteFieldGraphic::z () const [virtual]

This abstract method should return the z of the graphic, which is used for visual order: higher z sprites obscure lower-z ones.

Reimplemented in QwTextSprite.


This file is copyright © 1995-97 Warwick Allison.

It was generated from the following files:


Generated at 18:55, 1998/01/23 for Qt version 1.4 by the warwick at Troll Tech