PDA

View Full Version : help scene()->collidingItems



giorgik
2nd October 2012, 12:43
Hi all,
I have a problem of this kind, the management of collisions. To check if I have collision I use:

if(scene()->collidingItems(this).isEmpty()) (this condition is carried out inside my robot item)
when the condition is true, I would like to know against which item I had a collision with my item robot ?

wysota
2nd October 2012, 12:51
collidingItems() returns a list of items the given item collides with.

giorgik
2nd October 2012, 13:46
Yes wysota, but given that I would get the name of the item (item robot collides with item obstacle), how do I?
The problem could be solved using:
if(collidesWithItem(ostacolo)) ... having created a class Robot, derived from QGraphicsSvgItem, to see the class Obstacle (also derived from QGraphicsSvgItem) from that class I have to pass the reference to the instance Robot Obstacle, which I would rather avoid doing. So here is the need to extract the data from the list Obstacle collision. How to do this ?

wysota
2nd October 2012, 14:17
Yes wysota, but given that I would get the name of the item (item robot collides with item obstacle), how do I?
Use regular C++ means to identify the item (e.g. comparing it against a stored pointer) or use rtti offered by QGraphicsItem (i.e. QGraphicsItem::type()). If you just need to know if an item collides with a particular single item then ask the framework about the collision directly (using collidesWithItem()).