Collosion detection for QGraphicsPixmapItem objects. how?
hello eveyone :)
I'm making a time trial platformer game in qt5.
I'm trying to detect collosions between the instances of the Background class but it's not working.
[through qDebug(), I found out that it's not even entering the for loop.]
Background class is a subclass of the QGraphicsPixmapItem.
all of the platforms that the player jumps on, are instances of the Background class.
myscene is an instance of the Myscene class which is a subclass of the QGraphicsScene.
m_player is an instance of the Player class which is a subclass of the QGraphicsPixmapItem.
checkcollosion() is called every time scene gets updated.
Code:
void Myscene::checkcollosion()
{
QList<QGraphicsItem*> items = collidingItems(m_player);
for (int i=0, number = items.count(); i<number; ++i)
{
if (Background *back = qgraphicsitem_cast<Background*>(items.at(i)))
{
}
}
}
I guess because Background is a subclass of QGraphicsPixmapItem, the collidingItems() doesn't work for it.
and can qgraphicsitem_cast be used for casting QGraphicPixmapItem or is it only for QGraphicsItem ?
so how can I fix this?
Re: Collosion detection for QGraphicsPixmapItem objects. how?
Quote:
Originally Posted by
curiouscoding
I guess because Background is a subclass of QGraphicsPixmapItem, the collidingItems() doesn't work for it.
Not sure why you mean it wouldn't work for pixmap items, they do have a shape.
Quote:
Originally Posted by
curiouscoding
and can qgraphicsitem_cast be used for casting QGraphicPixmapItem or is it only for QGraphicsItem ?
A QGraphicsPixmapItem is a QGraphicsItem. So yes.
Cheers,
_