TexturePackerSpriteVPlay

The TexturePackerSpriteVPlay element defines a series of sprite frames within an image for a TexturePackerSpriteSequenceVPlay. It has an increased performance thanks to its support for sprite sheets created with TexturePacker. More...

Import Statement: import VPlay 2.0
Inherits:

TexturePackerAnimatedSpriteVPlay

Properties

Detailed Description

The TexturePackerSpriteVPlay component is needed for the TexturePackerSpriteSequenceVPlay like the Sprite is needed for the SpriteSequence. It supports sprite sheet created with TexturePacker. It also has an improved performance compared to the Sprite and SpriteVPlay 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.

This component is derived from {TexturePackerAnimatedSpriteVPlay}. It adds two new properties, name and to. Additionally it changes some default values.

The name property can be seen as the identifier of a state in a stochastic state machine and the to property describes this state's transitions to other states.

Both visible and running are also false by default because the TexturePackerSpriteSequenceVPlay handles them. The same applies to loops, which is set to TexturePackerSprite.Infinite by default.

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}
             }
         }
     }
 }

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

name : string

A string containing a unique identifier within the TexturePackerSpriteSequenceVPlay for this sprite. The name is used in the to property or the jumpTo() method. The TexturePackerSpriteSequenceVPlay uses this identifier to access its TexturePackerSpriteVPlay children.

The default value is an empty string, so you need to set it if you define multiple sprites to avoid conflicts.


to : var

This property is a QVariantMap, which is an object with number properties in JavaScript. The TexturePackerSpriteSequenceVPlay uses this map to determine which sprite it will animate next when the current sprite has run a complete cycle. The property names in this object are strings, which contain the name of a TexturePackerSpriteVPlay in the same TexturePackerSpriteSequenceVPlay. You can also use the name of this TexturePackerSpriteVPlay if you want a probability to stay in this sprite. The values of these properties say how probable it is to choose this sprite next.

Basically, this property defines the transitions of a stochastic state machine. And the TexturePackerSpriteVPlay children of the TexturePackerSpriteSequenceVPlay are the states.

Default is null, so you need to set it or this sprite will run forever.

Here is an example of how to use it:

 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}
             }
         }
     }
 }

The TexturePackerSpriteSequenceVPlay 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.

Note: "{"jump": 1, "walk": 3}" is equal to "{"jump": 0.25, "walk": 0.75}". You don't need to calculate the exact probabilities. Just use relative values.


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