AnimatedSprite QML 類型

Draws a sprite animation. 更多...

import 語句: import QtQuick 2.15
繼承:

Item

特性

信號

方法

詳細描述

AnimatedSprite provides rendering and control over animations which are provided as multiple frames in the same image file. You can play it at a fixed speed, 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:

To play each of these frames at a speed of 500 milliseconds per frame, the following code can be used:

代碼 結果
AnimatedSprite {
    source: "loading.png"
    frameWidth: 64
    frameHeight: 64
    frameCount: 4
    frameDuration: 500
}
								

By default, the frames are interpolated (blended together) to make the animation appear smoother. To disable this, set interpolate to false :

代碼 結果
AnimatedSprite {
    source: "loading.png"
    frameWidth: 64
    frameHeight: 64
    frameCount: 4
    frameDuration: 500
    interpolate: false
}
								

To control how AnimatedSprite responds to being scaled, use the smooth 特性。

Note that unlike SpriteSequence , the AnimatedSprite type does not use Sprite to define multiple animations, but instead encapsulates a single animation itself.

另請參閱 子畫麵動畫 .

特性文檔編製

currentFrame : int

When paused, the current frame can be advanced manually by setting this property or calling advance() .

finishBehavior : enumeration

The behavior when the animation finishes on its own.

常量 描述
FinishAtInitialFrame When the animation finishes it returns to the initial frame. This is the default behavior.
FinishAtFinalFrame When the animation finishes it stays on the final frame.

frameCount : int

Number of frames in this AnimatedSprite .

frameDuration : int

Duration of each frame of the animation in milliseconds. Values less than or equal to 0 are invalid.

frameRate is valid, it will be used to calculate the duration of the frames. If not, and frameDuration is valid, frameDuration 會被使用。

Changing this parameter will restart the animation.

frameHeight : int

Height of a single frame in this AnimatedSprite .

May be omitted if it is the only sprite in the file.

frameRate : qreal

Frames per second to show in the animation. Values less than or equal to 0 are invalid.

frameRate is valid, it will be used to calculate the duration of the frames. If not, and frameDuration is valid, frameDuration 會被使用。

Changing this parameter will restart the animation.

frameSync : bool

true , the animation will have no duration. Instead, the animation will advance one frame each time a frame is rendered to the screen. This synchronizes it with the painting rate as opposed to elapsed time.

If frameSync is set to true, it overrides both frameRate and frameDuration .

默認為 false .

Changing this parameter will restart the animation.

frameWidth : int

Width of a single frame in this AnimatedSprite .

May be omitted if it is the only sprite in the file.

frameX : int

The X coordinate in the image file of the first frame of the AnimatedSprite .

May be omitted if the first frame starts in the upper left corner of the file.

frameY : int

The Y coordinate in the image file of the first frame of the AnimatedSprite .

May be omitted if the first frame starts in the upper left corner of the file.

interpolate : bool

If true, interpolation will occur between sprite frames to make the animation appear smoother.

默認為 true。

loops : int

After playing the animation this many times, the animation will automatically stop. Negative values are invalid.

If this is set to AnimatedSprite.Infinite the animation will not stop playing on its own.

默認為 AnimatedSprite.Infinite

paused : bool

When paused, the current frame can be advanced manually.

默認為 false .

reverse : bool

true , the animation will be played in reverse.

默認為 false .

running : bool

Whether the sprite is animating or not.

默認為 true

source : url

The image source for the animation.

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 rectangluar frames, when one row runs out the next will be used.

frameX and frameY are specified, the row of frames will be taken with that x/y coordinate as the upper left corner.

信號文檔編製

finished ()

This signal is emitted when the sprite has finished animating.

It is not emitted when running is set to false , nor for sprites whose loops property is set to AnimatedSprite.Infinite .

注意: 相應處理程序是 onFinished .

該信號在 Qt 5.12 引入。

方法文檔編製

int advance ()

Advances the sprite animation by one frame.

int pause ()

Pauses the sprite animation. This does nothing if paused is true .

另請參閱 resume() .

int restart ()

停止,然後啓動子畫麵動畫。

int resume ()

再繼續子畫麵動畫,若 paused is true ;否則,這什麼都不做。

另請參閱 pause() .

start ()

Starts the sprite animation. If the animation is already running, calling this method has no effect.

該方法在 Qt 5.15 引入。

另請參閱 stop() .

stop ()

Stops the sprite animation. If the animation is not running, calling this method has no effect.

該方法在 Qt 5.15 引入。

另請參閱 start() .