-
Task
-
Resolution: Fixed
-
P2: Important
-
6.3.0
-
None
Proposing that we implement a new "FrameTimer" (or other suitable named) Qt Quick element which would help synchronizing with the scene refresh. Currently this isn't easy to do, see comments from QTBUG-98339.
The API could contain at least these:
Properties:
- int frame (Frame number 0..inf while animation is running)
- real frameTime (Time in seconds since the previous screen update)
- real elapsedTime (Time in seconds since the start)
- bool running
- bool paused
Slots:
- pause()
- restart()
- resume()
- start()
- stop()
Here are few use-cases for this element:
1) Animate things freely in-sync with other animations. NumberAnimations etc. can't be really used if "speed" can be freely changed.
FrameTimer { running: true onFrameChanged: { // Move item speed px/s, no matter what the speed, screen Hz or fps is. myItem.x += frameTime * speed; } }
2) Get fps without "dummy rotating item" hack.
property real fps FrameTimer { running: true onFrameChanged: { // Get current fps fps = 1.0 / frameTime; // Easy to calculate also average fps from longer period } }
3) Get real frame number for ShaderEffect (see e.g. how Shadertoy uses this). Also get elapsed time easily (Timer doesn't expose this, so need to maintain it manually, or e.g. use NumberAnimation or JS Date) as well as time delta (frame time).
FrameTimer { id: frameTimer running: true // Allow (re)starting and stopping this } ShaderEffect { property int iFrame: frameTimer.frame property real iTime: frameTimer.elapsedTime property real iTimeDelta: frameTimer.frameTime ... }
For Gerrit Dashboard: QTBUG-102641 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
408992,10 | Implement FrameAnimation Quick element | dev | qt/qtdeclarative | Status: MERGED | +2 | 0 |