The Sprite element defines a series of sprite frames within an image for a SpriteSequenceVPlay. More...

Import Statement: import VPlay 2.0



Detailed Description

The Sprite component specifies a single sprite animation. A sprite animation is a series of single images (also called a sprite frame) which get played after each other depending on the frameRate. To fully specify a sprite, at least the following properties are required: frameCount, frameWidth, frameHeight, source and either frameRate, frameDuration or duration.

Note: For sprites with improved performance use TexturePackerSpriteVPlay instead.

V-Play Additions to Sprite

SpriteVPlay enhances the Qt 5 component Sprite with Content Scaling and Dynamic Image Switching Support.

Specifically, it allows you to:

Sprite Example

A sample image of a sprite looks like this image:

The sprite consists of 4 frames with 32x32 pixels each, which can be played shortly after each other to simulate a fluid movement. After the last frame is reached, the animation starts at the first frame again. So for this image, the Sprite definition looks like the following:

 SpriteSequenceVPlay {

   SpriteVPlay {
     frameWidth: 32
     frameHeight: 32
     source: "squaby-sprite-walking.png"

     // update the animation 20 times per second
     frameRate: 20

Note: With the current version of V-Play and current version of Qt 5, the frames of a Sprite must be placed next to each other horizontally in a single image file. Sprite frames can wrap and continue in the next row though, to adhere with texture size limits which is mostly 2048 pixels for low-end devices or 4096 pixels for high-end devices.

For a performance-enhanced Sprite component which does not have this restriction, use TexturePackerSpriteVPlay.

Sprite and SpriteSequence

A Sprite is not rendered on its own. Instead, a Sprite is part of a SpriteSequenceVPlay which takes care of the rendering. Multiple Sprites can be part of a SpriteSequenceVPlay, which allows switching the currenlty running Sprite animation. For more details see the SpriteSequenceVPlay documentation.

If your animation of a game entity only consists of a single Sprite animation, use the AnimatedSpriteVPlay component instead. So if you want to switch between multiple Sprites, use SpriteSequenceVPlay, otherwise AnimatedSpriteVPlay.

For example, a game entity could have multiple states: walking, jumping, whirled by a weapon and dying. These states are exclusive, that means at any time the entity can only be in one of them. Thus only one should be played at a time, which makes it a perfect match for a SpriteSequenceVPlay. The image for the combined states looks like this:

Property Documentation

duration : alias

durationVariation : alias

frameCount : alias

frameDuration : alias

frameDurationVariation : alias

frameHeight : int

frameRate : alias

frameRateVariation : alias

frameSync : alias

frameWidth : int

frameX : int

frameY : int

name : alias

randomStart : alias

reverse : alias

source : alias

startFrameColumn : int

An alternative to defining frameX, the left position of the first frame in the Sprite animation. If set, the frameX property is automatically calculated based on the column number by multiplying it with the frameWidth.

Note: The first colum (so the left-most frame) starts with column 1, not 0.

startFrameRow : int

An alternative to defining frameY, the top position of the first frame in the Sprite animation. If set, the frameY property is automatically calculated based on the row number by multiplying it with the frameHeight.

Note: The first row (so the top-most frame) starts with row 1, not 0.

to : alias

See Sprite::to.

Voted #1 for:

  • Easiest to learn
  • Most time saving
  • Best support

Develop Cross-Platform Apps and Games 50% Faster!

  • Voted the best supported, most time-saving and easiest to learn cross-platform development tool
  • Based on the Qt framework, with native performance and appearance on all platforms including iOS and Android
  • Offers a variety of plugins to monetize, analyze and engage users
create apps
create games
cross platform
native performance
3rd party services
game network
level editor
easiest to learn
biggest time saving
best support