
The frame in the top left would be the first frame, the frame in the top right would be the fifth frame, and then it would wrap to the next row (at pixel location 0,40 in the file) to read the sixth frame. If you specified the frame size as 40x40 pixels, and a frame count of 8, then it would read in the frames as they are numbered. Normally, the image is read from the top-left corner. For now, just consider the black numbers, and assume the squares are 40x40 pixels. They should be arranged in a contiguous line, which may wrap from the right edge of the file to a lower row starting from the left edge of the file (and which is placed directly below the previous row).Īs an example, take the above image. In order to animate the image, however, the sprite engine requires the image file to contain all of the frames of the animation. The file formats accepted by the sprite engine are the same as the file formats accepted by other QML types, such as Image. Note that by forcibly setting the animation, you can start playing the animation immediately. In this example, you could set it back to walking and change the goal animation to walking or to nothing (which would lead it to play the standing animation after the walking animation). Because the jumping animation does not transition to other states, it will still keep playing the jumping animation until the state is forced to change. If you then set the goal state to the jumping animation, it would finish the walking animation before playing the jumping animation. It would then continue to play the walking animation until the goal animation is unset, at which point it would switch to the standing animation after finishing the walking animation. If it was previously in the waiting animation, it would finish playing that, then play the standing animation, then play the walking animation. But if you set the goal animation to be the walking animation, it would play the walking animation when it finished the standing animation. This allows for a character who has a slightly animated and variable behavior while waiting.īecause there is a zero weight transition to the walking animation, the standing animation will not normally transition there. Because the weights for those transitions are one, zero and three respectively, he has a one in four chance of playing the waiting animation when the standing animation finishes, and a three in four chance of playing the standing animation again. From this state, barring external input, he will transition to either the waiting animation, the walking animation, or play the standing animation again.

The character starts by displaying the standing state. This allows you to easily insert a transitional animation between two different sprites.Īs an example, consider the above diagram which illustrates the sprites for a hypothetical 2D platform game character.

If you instruct it to gradually transition, then it will reach the target sprite by going through valid state transitions using the fewest number of intervening sprites (but ignoring relative weightings). You can arbitrarily force it to immediately start playing any sprite, or you can tell it to gradually transition to a given sprite. You can affect the currently playing sprite in two ways.

When a sprite animation finishes, the sprite engine will choose the next sprite randomly, based on the weighted transitions available for the sprite that just finished. Sprites can have weighted transitions to other sprites, or back to themselves. This is not the same as the states and transitions in Qt Quick, and is more like a conventional state machine. State MachineĪ primary function of the sprite engine is its internal state machine. The Qt Quick sprite engine is a stochastic state machine combined with the ability to chop up images containing multiple frames of an animation.
