Game Programming using Qt 5 Beginner's Guide
上QQ阅读APP看书,第一时间看更新

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();
}
}
}