Whether the player item collides with a coin is checked by the scene's checkColliding() function, which is called after the player item has moved horizontally or vertically.
Item collision detection
Time for action - Making the coins explode
The implementation of checkColliding() looks like this:
void MyScene::checkColliding()
{
for(QGraphicsItem* item: collidingItems(m_player)) {
if (Coin *c = qgraphicsitem_cast<Coin*>(item)) {
c->explode();
}
}
}
What just happened?
First, we call the scene's QGraphicsScene::collidingItems...