
Originally Posted by
Blade
Hi guys!
I want to programm a little game in worms style. Now I need to check collisions between my Characters and my foreground picture(map).
What i don't know is how to implement collision detection with the map(is also a QGraphicsItem) as no rectangle.
I wanted to do this by writing a new QGraphicsItem::shape() function. But for this i need to do a QPainterPath from my map and I think theres no function to do a QPainterPath of a QPixmap?
You can implement
QGraphicsItem::collidesWithItem(const QGraphicsItem * other, Qt::ItemSelectionMode mode)
To copy to clipboard, switch view to plain text mode
and check whether other item is the item you wanted to check for collision and take necessary action (if you know the constraints properly). This may sometimes increase the performance too without need to reimplement shape().
Easier suggestion would be to implement shape() and manually return the boundary(as QPainterPath). This shouldn't be that difficult if your pixmap is not very complicated since you just need to return path in local coordinates. Remember you should just return boundary of your item.
Bookmarks