In this example, we will learn how to create sprite animation in QML.
Sprite animation
How to do it...
Let's make a horse run across our application window by following these steps:
- We will need to add our sprite sheet to Qt's resource system so that it can be used in the program. Open up qml.qrc and click the Add | Add Files buttons. Select your sprite sheet image and save the resource file by pressing Ctrl + S.
- Create a new empty window in main.qml:
import QtQuick 2.9
import QtQuick.Window 2.3
Window {
visible: true
width: 420
height: 380
Rectangle {
anchors.fill: parent
color: "white"
}
}
- Once you are done with that, we will start creating an AnimatedSprite object in QML...