Time for action – Adding jumping with sprite transitions

Let's replace the AnimatedSprite class with the SpriteSequence class in the Bejamin the Elephant animation, adding a sprite to be played during the jumping phase.

Open the Player.qml file and replace the AnimatedSprite object with the following code:

SpriteSequence {    id: sprite    width: 80    height: 52    interpolate: false    anchors.bottom: parent.bottom    anchors.horizontalCenter: parent.horizontalCenter    running: true    Sprite {        name: "still"        source: "images/sprite.png"        frameCount: 1        frameWidth: 80; frameHeight: 52        frameDuration: 100        to: { "still": 1, "walking": 0, "jumping": 0 }    }    Sprite {        name: "walking"        source: "images/sprite.png"        frameX: 560; frameY: 0        frameCount: 7 frameWidth: 80; frameHeight: ...

Get Game Programming using Qt 5 Beginner's Guide - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.