Game Development Reference
In-Depth Information
diffx = fabs(_foreground->getPositionX()) -
_foreground ->getContentSize().width * 4;
_foreground->setPositionX(-diffx);
}
4. We also employ our cloud sprites in the parallax effect. Since they appear be-
hind the cityscape, so even farther away from _player , the clouds move at an
even lower rate ( 0.15 ):
for (auto cloud : _clouds) {
cloud->setPositionX(cloud->getPositionX() -
_player->getVector().x * 0.15f);
if (cloud->getPositionX() +
cloud->getBoundingBox().size.width * 0.5f < 0 ) {
cloud->setPositionX(_screenSize.width +
cloud->getBoundingBox().size.width * 0.5f);
}
}
Search WWH ::




Custom Search