You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/Getting started.md
+2-36Lines changed: 2 additions & 36 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,39 +24,5 @@ int main(int argc, char **argv) {
24
24
The \link libscratchcpp::Project::run() run() \endlink method runs an event loop which stops after all scripts finish.
25
25
26
26
For CLI project players, using \link libscratchcpp::Project::run() run() \endlink is enough. If you are developing
27
-
a GUI project player and need to receive input events such as key presses, you'll need to implement your own event loop
28
-
or use the one provided by the GUI framework.
29
-
30
-
## GUI example (Qt)
31
-
Qt provides an event loop which can be easily used to run frames with a specific frame rate.
32
-
33
-
For example, a `Player` class which **inherits from QObject** can use a timer:
34
-
```cpp
35
-
#include <QObject>
36
-
#include <scratchcpp/project.h>
37
-
38
-
class Player : public QObject {
39
-
Q_OBJECT
40
-
public:
41
-
Player(QObject *parent = nullptr);
42
-
Player(const Player &) = delete; // Project is not copyable
43
-
44
-
protected:
45
-
void timerEvent(QTimerEvent *event) override;
46
-
47
-
private:
48
-
libscratchcpp::Project m_proj;
49
-
}
50
-
51
-
Player::Player(QObject *parent) {
52
-
m_proj.setFileName("/path/to/project.sb3");
53
-
m_proj.start();
54
-
int fps = 30;
55
-
startTimer(1000.0 / fps);
56
-
}
57
-
58
-
void Player::timerEvent(QTimerEvent *event) {
59
-
m_proj.frame();
60
-
event->accept();
61
-
}
62
-
```
27
+
a GUI project player and need to receive input events such as key presses, you'll need to use \link libscratchcpp::Project::runEventLoop() runEventLoop() \endlink
28
+
and run it in another thread (to keep the UI responsive).
0 commit comments