April 2018
Beginner
714 pages
18h 21m
English
The scene will create a graphics item for each part of the background and store pointers to them in the m_sky, m_grass, and m_trees private fields. Now the question is how to move them at different speeds. The solution is quite simple—the slowest one, the sky, is the smallest image. The fastest background, the ground and the grass, are the largest images. Now when we take a look at the end of the movePlayer() function's slot, we see this:
qreal ratio = qreal(m_worldShift) / maxWorldShift; applyParallax(ratio, m_sky); applyParallax(ratio, m_grass); applyParallax(ratio, m_trees);
The applyParallax() helper method contains the following code:
void MyScene::applyParallax(qreal ratio, QGraphicsItem* item) ...
Read now
Unlock full access