I am developing a game with QtQuick 2 (Qt5.2) QML and C ++. I want most of the game logic in C ++ (I don't want to do this with JS), and I'm trying to use QStateMachines for more logic.
Now my question is: how do I implement the correct game loop in this scenario?
In the game there are, for example, objects that move from and to certain waypoints on the screen, so I think I canโt do everything based on state / events. At some point I need to say: "My object should move 10 pixels in the x direction every second." For example, when my object is in the "move" state, it should move by a certain amount every second, and then, of course, check some conditions if it should switch the state (for example, to "attack").
Now all the demos in the Qt examples and on the Internet seem either completely event-based (for example, looking like four in a row), or written in JavaScript. So I got a little lost here.
One idea I could find was to create a QTimer with a timer, for example. 30 ms and connect the QTimer timeout () signal to the advance () interval of each moving object and start this timer until "return app.exec ();". Like this:
QTimer timer; QObject::connect(&timer, SIGNAL(timeout()), &scene, SLOT(advance())); timer.start(1000 / 33); return app.exec();
and then every object (like a mouse) has
void Mouse::advance(int step)
However, this requires a QGraphicsScene , and I'm not sure how well this works with the QtQuick / QML project on Android / iOS.
This is a good decision? Or is my opinion about the problem somehow wrong, and I donโt need a game loop to achieve my goal?
The solution should not use any desktop applications from Qt, i.e. they should work on Android, iOS and desktop computers.
c ++ qt game-engine qtquick2
Ela782
source share