Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- _________
- main.qml:
- ...
- Sprite {
- id: mysprite
- src: "mysprite.png"
- frames: 5
- currentFrame: 0 // initial frame
- MouseArea {
- anchors.fill: parent
- onClicked: { sprite.currentFrame = (sprite.currentFrame + 1) % sprite.frames }
- }
- }
- ...
- ___________
- Sprite.qml:
- import Qt 4.7
- Rectangle {
- property string src: parent ? "" : "sprite-unittest.png"
- property int frames: parent ? 1 : 7
- property int currentFrame: 0
- width: sprite_image.sourceSize.width / frames
- height: sprite_image.sourceSize.height
- color: "transparent"
- clip: true
- Image {
- id: sprite_image
- source: src
- x: -currentFrame * (sprite_image.sourceSize.width / frames)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement