Skip to Content
Game Programming Using Qt Beginner's Guide
book

Game Programming Using Qt Beginner's Guide

by Witold Wysota, Lorenz Haas
January 2016
Beginner
512 pages
12h 35m
English
Packt Publishing
Content preview from Game Programming Using Qt Beginner's Guide

Time for action – moving the background

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 have a look at the end of the movePlayer() function's slot we see this:

qreal ff = qMin(1.0, m_skippedMoving/(m_fieldWidth - width()));
m_sky->setPos(-(m_sky->boundingRect().width() - width()) * ff, 0);
m_grass->setPos(-(m_grass->boundingRect().width() - width()) * ff, m_grass->y());
m_trees->setPos(-(m_trees->boundingRect().width() - width()) * ff, m_trees->y());
m_ground->setPos(-(m_ground->boundingRect().width() - width()) * ff, m_ground->y());

What just happened?

What are we doing here? ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Game Programming using Qt 5 Beginner's Guide - Second Edition

Game Programming using Qt 5 Beginner's Guide - Second Edition

Pavel Strakhov, Witold Wysota, Lorenz Haas
Programming with Qt, 2nd Edition

Programming with Qt, 2nd Edition

Matthias Kalle Dalheimer

Publisher Resources

ISBN: 9781782168874Supplemental Content