[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-games-devel
Subject: [Kde-games-devel] Re: QCanvasSprite + QObject
From: Andreas Beckermann <b_mann () gmx ! de>
Date: 2001-12-12 20:43:29
[Download RAW message or body]
On Wednesday 12 December 2001 20:08, Johnny Andersson wrote:
> Hi.
Hi
> Is it possible to inherit from both QCanvasSprite and QObject at the
> same time?
Yes, this is possible - at least IIRC. Boson did this once.
> My program doesn't compile when I do. I've written my own sprite
Why? Can you post the error message=
> class, derived from QObject. I started having trouble when I wanted to use
> collision detection; to use RTTI, I have to derive from QCanvasItem.
>
> As a temporary solution, I created a small class derived form QCanvasSprite
> with the rtti-stuff. This class contains a pointer to my "real" sprite
> object, so that I can find it when Qt reports a collision. An ugly hack.
Well, my test code compiles:
Header:
#include <qobject.h>
#include <qcanvas.h>
class A : public QObject, QCanvasSprite
{
public:
A() : QObject(0), QCanvasSprite(0,0) { }
~A() { }
};
This doesn't do anything useful though. You'll also need to add a rtti() to be
able to use this at all. But it compiles here.
> Is it just me, or does the QCanvas extension not feel as polished as the
> rest of Qt? While very useful, there are some things that I've had to
> re-design in my program to work around. For example, QCanvasPixmapArray has
> a method setImage(...) to set a specific image in the list, and if needed,
> it extends the list. But I can't create an empty QCanvasPixmapArray and
> then add items to it using setImage, I have to create a dummy array first
> *or* create an empty QCanvasPixmapArray and then call readPixmaps (which if
> of course only relevant if you have the graphics in a file, and not
> generate them yourself).
WHat about this:
QValueList<QPixmap> pixmapList;
for(int i = 0; i < pixmaps; i++) {
QPixmap p = loadPixmap(i);
pixmapList.push_back(p); // aka append()
}
QCanvasPixmapArray* pixmapArray = new QCanvasPixmapArray(pixmapList);
if (!pixmapArray->isValid()) {
return false;
}
// ...
This pixmapArray can now be used by you. This is the way we do it in boson -
the pixmapArray is stored as a pointer so that we can use it for all units of
this type and don't have to reload it again. Remember to delete the pointer.
CU
Andi
_______________________________________________
kde-games-devel mailing list
kde-games-devel@mail.kde.org
http://mail.kde.org/mailman/listinfo/kde-games-devel
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic