C
AnimatedSprite QML Type
Draws a sprite animation. More...
Import Statement: | import QtQuick |
Since: | Qt Quick Ultralite 2.3 |
Inherits: |
Properties
- currentFrame : int
- frameCount : int
- frameDuration : int
- frameHeight : int
- frameWidth : int
- loops : int
- paused : bool
(since Qt Quick Ultralite 2.5)
- running : bool
- source : string
Signals
- finished()
Methods
- advance()
- pause()
(since Qt Quick Ultralite 2.5)
- restart()
- resume()
(since Qt Quick Ultralite 2.5)
- start()
- stop()
Detailed Description
AnimatedSprite renders and controls animations that are provided as multiple frames in one image file. You can play it either at a fixed speed, or manually advance and control the progress.
Consider the following sprite sheet:
It can be divided up into four frames:
Use the following code to play each of these frames at a speed of 500 milliseconds per frame:
Code | Result |
---|---|
import QtQuick 2.15 AnimatedSprite { source: "loading.png" frameWidth: 64 frameHeight: 64 frameCount: 4 frameDuration: 500 } |
Property Documentation
currentFrame : int
Set this property to advance the current frame manually, when the animation is paused. You could also call the advance() method.
frameCount : int
Indicates the number of frames in the AnimatedSprite.
frameDuration : int
Duration of each frame of the animation in milliseconds. Only positive values are valid.
Changing this property while the animation is active, will restart the animation.
frameHeight : int
Set the height of a single frame in the AnimatedSprite.
frameWidth : int
Set the width of a single frame in the AnimatedSprite.
loops : int
After playing the animation this many times, the animation will automatically stop. Only positive values are valid.
Set it to AnimatedSprite.Infinite
to play the animation infinitely.
Default is AnimatedSprite.Infinite
.
paused : bool [since Qt Quick Ultralite 2.5]
Indicates whether the animation is paused or not.
When the animation is paused, you can advance its current frame manually.
Default is false
This property was introduced in Qt Quick Ultralite 2.5.
running : bool
Indicates whether the animation is playing or not.
Default is true
source : string
The image source for the animation.
Specifying the frame size of the image source with ImageFiles.MCU.resourceAnimatedSpriteFrameWidth and ImageFiles.MCU.resourceAnimatedSpriteFrameHeight enables resource optimization by splitting the image into frame sequences and sharing common parts between them.
See also Managing Resources.
Signal Documentation
finished()
This signal is emitted when the sprite animation completes.
It is not emitted if either the running
property is set to false
or the loops
property is set to AnimatedSprite.Infinite
.
Note: The corresponding handler is onFinished
.
Method Documentation
advance()
Advances the sprite animation by one frame.
[since Qt Quick Ultralite 2.5]
pause()
Pauses the sprite animation. This does nothing if paused is true
.
This method was introduced in Qt Quick Ultralite 2.5.
restart()
Restarts the sprite animation.
[since Qt Quick Ultralite 2.5]
resume()
Resumes the sprite animation if paused is true
. Otherwise, this does nothing.
This method was introduced in Qt Quick Ultralite 2.5.
start()
Starts the sprite animation. If the animation is already running, calling this method has no effect.
stop()
Stops the sprite animation. If the animation is not running, calling this method has no effect.
Available under certain Qt licenses.
Find out more.