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
- running : bool
- source : string
Signals
- finished()
Methods
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 and at the frame rate of your display, 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 parameter will restart the animation.
frameHeight : int |
Set the height of a single frame in the AnimatedSprite.
Note: You need not set this property if the file has only one sprite.
frameWidth : int |
Set the width of a single frame in the AnimatedSprite.
Note: You need not set this property if the file has only one sprite.
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
.
running : bool |
Indicates whether the animation is playing or not.
Default is true
source : string |
The image source for the animation.
If frameHeight and frameWidth are not specified, it is assumed to be a single long row of square frames. Otherwise, it can be multiple contiguous rows or rectangular frames.
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.
restart() |
Restarts the sprite animation.
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.