O'Reilly logo

Game Programming using Qt 5 Beginner's Guide - Second Edition by Lorenz Haas, Witold Wysota, Pavel Strakhov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action – receiving mouse input

Our game is pretty simple, so the only action the player has to do is pick two rods for a move. Let's use ObjectPicker to detect when the player clicks on a rod.

First, set the pickingSettings.pickMethod property of the RenderSettings object to PickingSettings.TrianglePicking in the main.qml file (you can use the code example from the previous section). Our scene is very simple, and triangle picking shouldn't be too slow. This setting will greatly increase the picker's accuracy.

The next set of changes will go to the Rod.qml file. First, add an ID to the root entity and declare a signal that will notify the outside world that the rod was clicked:

Entity {    id: rod    property int index readonly property ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required