January 2016
Beginner
512 pages
12h 35m
English
The implementation of checkColliding() looks like this:
QList<QGraphicsItem*> items = collidingItems(m_player);
for (int i = 0, total = items.count(); i < total; ++i) {
if (Coin *c = qgraphicsitem_cast<Coin*>(items.at(i)))
c->explode();
}First we call the scene's QGraphicsScene::collidingItems() function, which takes the item for which colliding items should be detected as a first argument. With the second, optional argument, you could define how the collision should be detected. The type of that argument is Qt::ItemSelectionMode, which was explained earlier. In our case, a list of all the items that collide with m_player will be returned. So we loop through that list and check whether ...