三个碰撞检测函数
该图形项是否与指定的图形项碰撞
bool QGraphicsItem::collidesWithItem(const QGraphicsItem *other, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape) const
该图形项是否与指定的路径碰撞
bool QGraphicsItem::collidesWithPath(const QPainterPath &path, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape) const
返回所有与该图形项碰撞的图形项的列表
QList<QGraphicsItem *> QGraphicsItem::collidingItems(Qt::ItemSelectionMode mode = Qt::IntersectsItemShape) const
其中,参数 Qt::ItemSelectionMode 有4个值
Qt::ContainsItemShape :只有图形项的shape被完全包含时;
Qt::IntersectsItemShape :当图形项的shape被完全包含时,或者图形项与其边界相交;
Qt::ContainsItemBoundingRect : 只有图形项的bounding rectangle被完全包含时;
Qt::IntersectsItemBoundingRect :图形项的bounding rectangle被完全包含时,或者图形项与其边界相交。(常用)
可以用来实现游戏等功能,但一般人还是喜欢自定义碰撞检测函数,如果要做简单的小游戏用这些qt自实现的函数还是很方便的
这篇博客介绍了Qt库中用于图形项碰撞检测的三个函数,包括与特定图形项、路径的碰撞检测以及获取所有碰撞图形项的列表。讨论了Qt::ItemSelectionMode的四种模式,并指出它们在游戏等应用中的实用性。尽管自定义碰撞检测可能更灵活,但Qt提供的函数对于简单游戏开发来说非常方便。

2036

被折叠的 条评论
为什么被折叠?



