Book description
A complete guide to designing and building fun games with Qt and Qt Quick using associated toolsets
About This Book- A step by step guide to learn Qt by building simple yet entertaining games
- Get acquainted with a small yet powerful addition - Qt Gamepad Module, that enables Qt applications to support the use of gamepad hardware
- Understand technologies such as QML, OpenGL, and Qt Creator to design intuitive games
If you want to create great graphical user interfaces and astonishing games with Qt, this book is ideal for you. No previous knowledge of Qt is required; however knowledge of C++ is mandatory.
What You Will Learn- Install the latest version of Qt on your system
- Understand the basic concepts of every Qt game and application
- Develop 2D object-oriented graphics using Qt Graphics View
- Build multiplayer games or add a chat function to your games with Qt Network module
- Script your game with Qt QML
- Explore the Qt Gamepad module in order to integrate gamepad support in C++ and QML applications
- Program resolution-independent and fluid UIs using QML and Qt Quick
- Control your game flow in line with mobile device sensors
- Test and debug your game easily with Qt Creator and Qt Test
Qt is the leading cross-platform toolkit for all significant desktop, mobile, and embedded platforms and is becoming popular by the day, especially on mobile and embedded devices. It's a powerful tool that perfectly fits the needs of game developers. This book will help you learn the basics of Qt and will equip you with the necessary toolsets to build apps and games.
The book begins by how to create an application and prepare a working environment for both desktop and mobile platforms. You will learn how to use built-in Qt widgets and Form Editor to create a GUI application and then learn the basics of creating graphical interfaces and Qt's core concepts.
Further, you'll learn to enrich your games by implementing network connectivity and employing scripting. You will learn about Qt's capabilities for handling strings and files, data storage, and serialization.
Moving on, you will learn about the new Qt Gamepad module and how to add it in your game and then delve into OpenGL and Vulcan, and how it can be used in Qt applications to implement hardware-accelerated 2D and 3D graphics. You will then explore various facets of Qt Quick: how it can be used in games to add game logic, add game physics, and build astonishing UIs for your games.
By the end of this book, you will have developed the skillset to develop interesting games with Qt.
Style and approachLearn Qt with the help of numerous sample games, introduced step-by-step in each chapter
Table of contents
- Title Page
- Copyright and Credits
- Dedication
- Packt Upsell
- Contributors
- Preface
- Introduction to Qt
- Installation
-
Qt GUI Programming
- Creating GUI in Qt
- Layouts
- Signals and slots
- Creating a widget for the tic-tac-toe board
- Advanced form editor usage
- Polishing the application
- Pop quiz
- Summary
-
Custom 2D Graphics with Graphics View
- Graphics View architecture
- Coordinate systems
- Overview of functionality
-
Custom items
- Time for action – Creating a sine graph project
- Time for action – Creating a graphics item class
- Events
- Time for action – Implementing the ability to scale the scene
- Time for action – Taking the zoom level into account
- Time for action – Reacting to an item's selection state
- Time for action – Event handling in a custom item
- Time for action – Implementing the ability to create and delete elements with mouse
- Time for action – Changing the item's size
- Have a go hero – Extending the item's functionality
- Widgets inside Graphics View
- Optimization
- Pop quiz
- Summary
- Animations in Graphics View
-
Qt Core Essentials
- Text handling
- Containers
- Data storage
- Pop quiz
- Summary
-
Networking
-
QNetworkAccessManager
- Setting up a local HTTP server
- Preparing a URL for testing
- Time for action – Downloading a file
- Have a go hero – Extending the basic file downloader
- Single network manager per application
- Time for action – Displaying a proper error message
- Downloading files over FTP
- Downloading files in parallel
- The finished signal
- Time for action – Writing the OOP conform code using QSignalMapper
- The error signal
- The readyRead signal
- Time for action – Showing the download progress
- Using a proxy
- Connecting to Google, Facebook, Twitter, and co.
- Controlling the connectivity state
- Communicating between games
- Using UDP
- Pop quiz
- Summary
-
QNetworkAccessManager
-
Custom Widgets
- Raster and vector graphics
- Raster painting
- Creating a custom widget
- Working with images
- Painting text
- Optimizing widget painting
-
Implementing a chess game
- Time for action – Developing the game architecture
- Time for action – Implementing the game board class
- Time for action – Understanding the ChessView class
- Time for action – Rendering the pieces
- Time for action – Making the chess game interactive
- Time for action – Connecting the game algorithm
- Have a go hero – Implementing the UI around the chess board
- Have a go hero – Connecting a UCI-compliant chess engine
- Pop quiz
- Summary
- OpenGL and Vulkan in Qt applications
-
Scripting
- Why script?
- Evaluating JavaScript expressions
-
Exposing C++ objects and functions to JavaScript code
- Accessing C++ object's properties and methods
- Data type conversions between C++ and JavaScript
- Accessing signals and slots in scripts
- Time for action – Using a button from JavaScript
- Restricting access to C++ classes from JavaScript
- Creating C++ objects from JavaScript
- Exposing C++ functions to JavaScript
- Creating a JavaScript scripting game
- Python scripting
- Pop quiz
- Summary
-
Introduction to Qt Quick
- Declarative UI programming
- Overview of QML types provided by Qt
-
Qt Quick Designer
- Time for action – Adding a form to the project
- Form editor files
- Form editor interface
- Time for action – Adding an import
- Time for action – Adding items to the form
- Time for action – Editing anchors
- Time for action – Applying layouts to the items
- Time for action – Assigning an expression to the property
- Time for action – Exposing items as properties
- Time for action – Creating an event handler
- Qt Quick and C++
- Bringing life into static user interfaces
- Pop quiz
- Summary
-
Customization in Qt Quick
- Creating a custom QML component
-
Event handlers
- Time for action – Making the button clickable
- Time for action – Visualizing button states
- Time for action – Notifying the environment about button states
- Touch input
- Time for action – Dragging an item around
- Time for action – Rotating and scaling a picture by pinching
- Keyboard input
- Text input fields
- Gamepad input
- Sensor input
- Detecting device location
- Creating advanced QML components
- Dynamic and lazy loading of QML objects
- Imperative painting on Canvas using JavaScript
- Using C++ classes as QML components
- Pop quiz
- Summary
-
Animations in Qt Quick Games
-
Animation framework in Qt Quick
- Generic animations
- Time for action – Scene for an action game
- Time for action – Animating the sun's horizontal movement
- Composing animations
- Time for action – Making the sun rise and set
- Non-linear animations
- Time for action – Improving the path of the sun
- Property value sources
- Time for action – Adjusting the sun's color
- Time for action – Furnishing sun animation
- Behaviors
- Time for action – Animating the car dashboard
- States
- Transitions
- More animation types
-
Quick game programming
- Game loops
- Input processing
- Time for action – Character navigation
- Time for action – Another approach to character navigation
- Time for action – Generating coins
- Sprite animation
- Time for action – Implementing simple character animation
- Time for action – Animating characters using sprites
- Time for action – Adding jumping with sprite transitions
- Time for action – Revisiting parallax scrolling
- Collision detection
- Time for action – Collecting coins
- Have a go hero – Extending the game
- Pop quiz
- Summary
-
Animation framework in Qt Quick
- Advanced Visual Effects in Qt Quick
- 3D Graphics with Qt
- Pop quiz answers
- Other Books You May Enjoy
Product information
- Title: Game Programming using Qt 5 Beginner's Guide - Second Edition
- Author(s):
- Release date: April 2018
- Publisher(s): Packt Publishing
- ISBN: 9781788399999
You might also like
book
Beginning C++ Game Programming - Second Edition
Get to grips with programming techniques and game development using C++ libraries and Visual Studio 2019 …
book
Introduction to Design Patterns in C++ with Qt, 2nd Edition
Master C++ “The Qt Way” with Modern Design Patterns and Efficient Reuse This fully updated, classroom-tested …
book
Programming with Qt, 2nd Edition
The popular open source KDE desktop environment for Unix was built with Qt, a C++ class …
book
Hands-On GUI Programming with C++ and Qt5
Create visually appealing and feature-rich applications by using Qt 5 and the C++ language About This …