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 ...

Get Game Programming using Qt 5 Beginner's Guide - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.