返回介绍

QCanvasPixmapArray Class

发布于 2019-10-04 14:58:41 字数 6782 浏览 853 评论 0 收藏 0

The QCanvasPixmapArray class provides an array of QCanvasPixmaps. More...

#include <qcanvas.h>

List of all member functions.

Public Members

  • QCanvasPixmapArray ()
  • QCanvasPixmapArray ( constQString&datafilenamepattern, intfc = 0 )
  • QCanvasPixmapArray ( QPtrList<QPixmap>list, QPtrList<QPoint>hotspots ) (obsolete)
  • QCanvasPixmapArray ( QValueList<QPixmap>list, QPointArrayhotspots = QPointArray ( ) )
  • ~QCanvasPixmapArray ()
  • bool readPixmaps ( constQString&filenamepattern, intfc = 0 )
  • bool readCollisionMasks ( constQString&filename )
  • bool operator! () (obsolete)
  • bool isValid () const
  • QCanvasPixmap * image ( inti ) const
  • void setImage ( inti, QCanvasPixmap*p )
  • uint count () const

Detailed Description

The QCanvasPixmapArray class provides an array of QCanvasPixmaps.

This class is used by QCanvasSprite to hold an array of pixmaps. It is used to implement animated sprites, i.e. images that change over time, with each pixmap in the array holding one frame.

Depending on the constructor you use you can load multiple pixmaps into the array, either from a directory (specifying a wildcard pattern for the files), or from a list of QPixmaps. You can also read in a set of pixmaps after construction using readPixmaps().

Individual pixmaps can be set with setImage() and retrieved with image(). The number of pixmaps in the array is returned by count().

QCanvasSprite uses an image's mask for collision detection. You can change this by reading in a separate set of image masks using readCollisionMasks().

See also Graphics Classes and Image Processing Classes.


Member Function Documentation

QCanvasPixmapArray::QCanvasPixmapArray ()

Constructs an invalid array (i.e. isValid() will return FALSE). You must call readPixmaps() before being able to use this QCanvasPixmapArray.

QCanvasPixmapArray::QCanvasPixmapArray ( constQString&datafilenamepattern, intfc = 0 )

Constructs a QCanvasPixmapArray from files.

The fc parameter sets the number of frames to be loaded for this image.

If fc is not 0, datafilenamepattern should contain "%1", e.g. "foo%1.png". The actual filenames are formed by replacing the %1 with four-digit integers from 0 to (fc - 1), e.g. foo0000.png, foo0001.png, foo0002.png, etc.

If fc is 0, datafilenamepattern is asssumed to be a filename, and the image contained in this file will be loaded as the first (and only) frame.

If datafilenamepattern does not exist, is not readable, isn't an image, or some other error occurs, the array ends up empty and isValid() returns FALSE.

QCanvasPixmapArray::QCanvasPixmapArray ( QPtrList<QPixmap>list, QPtrList<QPoint>hotspots )

This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.

Use QCanvasPixmapArray::QCanvasPixmapArray( QValueList, QPointArray ) instead.

Constructs a QCanvasPixmapArray from the list of QPixmaps list. The hotspots list has to be of the same size as list.

QCanvasPixmapArray::QCanvasPixmapArray ( QValueList<QPixmap>list, QPointArrayhotspots = QPointArray ( ) )

Constructs a QCanvasPixmapArray from the list of QPixmaps in the list. Each pixmap will get a hotspot according to the hotspots array. If no hotspots are specified, each one is set to be at position (0, 0).

If an error occurs, isValid() will return FALSE.

QCanvasPixmapArray::~QCanvasPixmapArray ()

Destroys the pixmap array and all the pixmaps it contains.

uint QCanvasPixmapArray::count () const

Returns the number of pixmaps in the array.

QCanvasPixmap* QCanvasPixmapArray::image ( inti ) const

Returns pixmap i in the array, if i is non-negative and less than than count(), and returns an unspecified value otherwise.

bool QCanvasPixmapArray::isValid () const

Returns TRUE if the pixmap array is valid; otherwise returns FALSE.

bool QCanvasPixmapArray::operator! ()

This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.

Use isValid() instead.

This returns FALSE if the array is valid, and TRUE if it is not.

bool QCanvasPixmapArray::readCollisionMasks ( constQString&filename )

Reads new collision masks for the array.

By default, QCanvasSprite uses the image mask of a sprite to detect collisions. Use this function to set your own collision image masks.

If count() is 1 filename must specify a real filename to read the mask from. If count() is greater than 1, the filename must contain a "%1" that will get replaced by the number of the mask to be loaded, similar to QCanvasPixmapArray::readPixmaps().

All collision masks must be 1-bit images or this function call will fail.

If the file isn't readable, contains the wrong number of images, or there is some other error, this function will return FALSE, and the array will be flagged as invalid; otherwise this function returns TRUE.

See also isValid().

bool QCanvasPixmapArray::readPixmaps ( constQString&filenamepattern, intfc = 0 )

Reads one or more pixmaps into the pixmap array.

If fc is not 0, filenamepattern should contain "%1", e.g. "foo%1.png". The actual filenames are formed by replacing the %1 with four-digit integers from 0 to (fc - 1), e.g. foo0000.png, foo0001.png, foo0002.png, etc.

If fc is 0, filenamepattern is asssumed to be a filename, and the image contained in this file will be loaded as the first (and only) frame.

If filenamepattern does not exist, is not readable, isn't an image, or some other error occurs, this function will return FALSE, and isValid() will return FALSE; otherwise this function will return TRUE.

See also isValid().

void QCanvasPixmapArray::setImage ( inti, QCanvasPixmap*p )

Replaces the pixmap at index i with pixmap p.

The array takes ownership of p and will delete p when the array itself is deleted.

If i is beyond the end of the array the array is extended to at least i+1 elements, with elements count() to i-1 being initialized to 0.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文