TexturePackerSpriteSequenceVPlay

The TexturePackerSpriteSequenceVPlay contains a list of TexturePackerSpriteVPlay elements and allows switching between them with only one active at a time. It has an increased performance thanks to its support for sprite sheets created with TexturePacker. More...

Import Statement: import VPlay 2.0
Inherits:

Item

Properties

Methods

Detailed Description

The TexturePackerSpriteSequenceVPlay component lets you control multiple sprite animations like the SpriteSequence. It supports sprite sheet created with TexturePacker. The TexturePackerSpriteSequenceVPlay component contains a list of TexturePackerSpriteVPlay and allows easy switching with only one active at a time. It also has an improved performance compared to the SpriteSequence and SpriteSequenceVPlay components.

Read the guide How to use TexturePacker with V-Play to know why sprite sheets reduce the memory consumption and improve the performance of your game.

The TexturePackerSpriteSequenceVPlay is a stochastic state machine. This means its states are the different sprites and a randomly chosen transition happens when a sprite finishes one animation cycle. The states are defined by the TexturePackerSpriteVPlay::name property and the transitions are defined through the TexturePackerSpriteVPlay::to property.

Example Usage

Here is an example of how to use two TexturePackerSpriteVPlay in a TexturePackerSpriteSequenceVPlay:

 import VPlay 2.0
 import QtQuick 2.0

 GameWindow {
     Scene {
         TexturePackerSpriteSequenceVPlay {

             TexturePackerSpriteVPlay {
                 name: "jump"
                 source: "../assets/img/squaby.json"
                 frameNames: ["squ1-jump-1.png", "squ1-jump-2.png", "squ1-jump-3.png", "squ1-jump-4.png"]
                 frameRate: 3

                 to: {"jump": 1, "walk": 3}
             }
             TexturePackerSpriteVPlay {
                 name: "walk"
                 source: "../assets/img/squaby.json"
                 frameNames: ["squ1-walk-1.png", "squ1-walk-2.png", "squ1-walk-3.png", "squ1-walk-4.png"]
                 frameRate: 3

                 to: {"jump": 1, "walk": 1}
             }
         }
     }
 }

This example will start with the first sprite called "jump". When this sprite has finished "walk" will be the next sprite with a probability of 3/4. The probability to stay in the "jump" sprite for one more cycle is the remaining 1/4. When the "walk" sprite finishes to probabilities for "jump" and "walk" are 50:50.

To change the active animation manually, use the jumpTo() function like in this example:

 import VPlay 2.0
 import QtQuick 2.0

 GameWindow {
   Scene {
     TexturePackerSpriteSequenceVPlay {
       id: squabySprite
       anchors.centerIn: parent

       TexturePackerSpriteVPlay {
         name: "walk"
         source: "../assets/img/squaby.json"
         frameNames: ["squ1-walk-1.png", "squ1-walk-2.png", "squ1-walk-3.png", "squ1-walk-4.png"]
         frameRate: 3
       }
       TexturePackerSpriteVPlay {
         name: "jump"
         source: "../assets/img/squaby.json"
         frameNames: ["squ1-jump-1.png", "squ1-jump-2.png", "squ1-jump-3.png", "squ1-jump-4.png"]
         to: {"jump": 1, "walk": 3}
         frameRate: 3
       }
     }// SpriteSequenceFromFile

     Row {
       anchors.bottom: parent.bottom // put on the bottom
       ButtonVPlay {
         text: "Jump"
         onClicked: {
           squabySprite.jumpTo("jump")
         }
       }// ButtonVPlay
       ButtonVPlay {
         text: "Walk"
         onClicked: {
           squabySprite.jumpTo("walk")
         }
       }// ButtonVPlay
     }// Row
   }
 }

This component supports content scaling to pick the best image quality for your screen density.

Property Documentation

currentSprite : string

The name of the TexturePackerSpriteVPlay, which is currently animating.


mirror : bool

This property holds whether the image should be horizontally mirrored.

The default value is false.


mirrorY : bool

This property holds whether the image should be vertically mirrored.

Note: Mirroring on the vertical axis is internally achieved by setting the Item::transform property. Thus if you set the transform property explicitly, you need to apply the y-scaling manually.

The default value is false.


running : bool

Whether the sprite is animating or not.

Default is true.


sprites : var

A read-only list of TexturePackerSpriteVPlay, which are the children of this TexturePackerSpriteSequenceVPlay. These sprites will be scaled to the size of this item.


Method Documentation

jumpTo(sprite)

This function causes the TexturePackerSpriteSequenceVPlay to jump to the specified sprite immediately. The sprite argument is the TexturePackerSpriteVPlay::name of the sprite you wish to jump to.


Videos

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
FREE!
create apps
create games
cross platform
native performance
3rd party services
game network
multiplayer
level editor
easiest to learn
biggest time saving
best support