How to handle multiple collision type in c++?
I'm building a game in c++ using Qt. I got the collision detection right using GraphicsItem methods the thing is that I don't know how to deal with every different collision type as there is different objects with different behaviour.
I guess that you are using one of the collidingItems
or collidesWithItem
methods. From these you get a list of QGraphicsItem
s. Then it is just a matter of casting to determine what hit what and reacting.
It's actually possible to know which kind of object participate in the collision, through custom type, see the documentation for more info http://doc.qt.io/qt-5/qgraphicsitem.html#type
精彩评论