[PyQt] PyQt4 does not recognize the *shape* of QGraphicsItems for collision detection
Konrad Koller
koko9991 at googlemail.com
Sat Aug 14 17:42:53 BST 2010
In many games collision detection is important. In my case the game's stones
are mostly convex polygons.
Therefore their bounding rectangle is not adequate for collision detection
and therefore I create them
in the constructor of the class Stone(QGraphicsItem) as QPainterPaths like
so:
self.path=QPainterPath()
self.path.addPolygon(polygon)
self.path.closeSubpath()
Then their shape is simple:
def shape(self): return self.path
Their boundingRect (used elsewhere) is:
def boundingRect(self): return self.path.boundingRect()
For collision detection with already placed stones I write:
for item in self.collidingItems(Qt.IntersectsItemShape):
if isinstance(item,Stone): print "Collision!"
To my surprise the detection does not recognize the shape but obviously the
boundingRect.
For example:
_________
|______ |
___ | |___
| | |_____|
| |
| |_
|____|
This reports a "collision". Why?
Thanks for any hint. Konrad
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20100814/51c117aa/attachment.html>
More information about the PyQt
mailing list