Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Game Programming using Qt 5 Beginner's Guide

You're reading from   Game Programming using Qt 5 Beginner's Guide Create amazing games with Qt 5, C++, and Qt Quick

Arrow left icon
Product type Paperback
Published in Apr 2018
Publisher
ISBN-13 9781788399999
Length 714 pages
Edition 2nd Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Pavel Vladimirovich Strakhov Pavel Vladimirovich Strakhov
Author Profile Icon Pavel Vladimirovich Strakhov
Pavel Vladimirovich Strakhov
Arrow right icon
View More author details
Toc

Table of Contents (18) Chapters Close

Preface 1. Introduction to Qt 2. Installation FREE CHAPTER 3. Qt GUI Programming 4. Custom 2D Graphics with Graphics View 5. Animations in Graphics View 6. Qt Core Essentials 7. Networking 8. Custom Widgets 9. OpenGL and Vulkan in Qt applications 10. Scripting 11. Introduction to Qt Quick 12. Customization in Qt Quick 13. Animations in Qt Quick Games 14. Advanced Visual Effects in Qt Quick 15. 3D Graphics with Qt 16. Pop quiz answers
17. Other Books You May Enjoy

Finishing the game

The last part we have to discuss is the scene's initialization. Set the initial values for all fields and the constructor, create the initPlayField() function that will set up all the items, and call that function in the constructor. First, we initialize the sky, trees, ground, and player item:

void MyScene::initPlayField()
{
setSceneRect(0, 0, 500, 340);
m_sky = new BackgroundItem(QPixmap(":/sky"));
addItem(m_sky);
BackgroundItem *ground = new BackgroundItem(QPixmap(":/ground"));
addItem(ground);
ground->setPos(0, m_groundLevel);
m_trees = new BackgroundItem(QPixmap(":/trees"));
m_trees->setPos(0, m_groundLevel - m_trees->boundingRect().height());
addItem(m_trees);
m_grass = new BackgroundItem(QPixmap(":/grass"));
m_grass->setPos(0,m_groundLevel - m_grass->boundingRect...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime