MovementAnimation

Modifies a property with a constant velocity and acceleration. More...

Import Statement: import

Properties

Signals

Methods

Detailed Description

This component modifies any property with a constant velocity and acceleration. Compared to the QML Animation elements, this component has a significant difference: You do not need to specify a duration. So the velocity and acceleration are applied endlessly, unless stop() is called or running is set to false.

You can use this component for any task where you do not know the target value and duration beforehand. For example when you want to move the parallax background layer of a level with a constant velocity. If this velocity should change over time, also an acceleration can be set.

For convenience, there are border properties which limit the calculations of the property value and the velocity. However, these are all optional. The only required parameters of this component is the target, the property and the running property.

Moving a Game Entity with MovementAnimation

With the MovementAnimation, you can animate any property of an object over time, but it is especially useful for positioning entities. You can move an entity from position A to B either with the physics-based components like BoxCollider and setting the ColliderBase::linearVelocity and ColliderBase::angularVelocity, or by using the MovementAnimation.

This example shows how to move an entity with a velocity of 100px per second to the right, and 50px per second to the bottom. So with this example, after 1 second the x position of the entity will be 100, and the y position 50:

 GameEntity {

   MovementAnimation {
     target: parent
     property: "pos"

     velocity: Qt.point(100, 50)

     // start running from the beginning
     running: true
   }
 }

Rotating a Game Entity with MovementAnimation

Similar to the movement, also the rotation can be changed over time. With the following example, the rotation is modified by an acceleration of 50. This means that the velocity will start with the initial setting 100 (so 100 degrees per second to the right as it is a positive value, a negative would rotate it counter-clockwise). And after 1 second, the velocity will be 150, because the acceleration defines how much the velocity changes each second. Consider this example:

 EntityBase {

   MovementAnimation {
     target: parent
     property: "rotation"

     velocity: 100
     acceleration: 50

     // start running from the beginning
     running: true
   }
 }

Advanced Usage

The following example combines all possible options. Usually, you will not need to set all of them, but for demonstration purposes:

 Rectangle {
   id: entity
   x: 30; y: 20
   width: 30; height: 20
   color: "blue"

   MovementAnimation {
     target: entity
     property: "x"
     running: true

     // the starting velocity
     velocity: 960

     // this forces the rectangle to move to the left (against the velocity direction), but it doesnt get faster than -20 px/second!
     acceleration: -260
     minVelocity: -20
     // limits the initial velocity set to 960, now to 500
     maxVelocity: 500

     // limits the x property between a border of 10 and 100
     minPropertyValue: 10
     maxPropertyValue: 100

     // never change the x value by more than 50 pixels in one step
     // this is useful for example to limit the rotation from MoveToPointHelper
     maxPropertyValueDifference: 50


     // this is the same as setting running to true, only for demonstration purpose
     //Component.onCompleted: movement.start()
   }
 }

Note: The API, i.e the properties and functions of this component are similar to the QML Animation elements, but they do not share the same base class. So some functions are different and some properties are not supported which do not make sense for this kind of animation. It also cannot be used in SequentialAnimation or ParallelAnimation containers, because the base class is not the same. However, adding MovementAnimations to these containers is not intended, because by its nature it has no fixed duration but runs endlessly. So any animations put after it in a SequentialAnimation would never be started.

Property Documentation

acceleration : variant

This property specifies how much the velocity changes per second. Can either be of type real or point (when the position should be modified).

If the acceleration is set to 10 for example, and the initial velocity is set to 20, it will be 30 after one second. Here is the source code for this example:

 Item {

   MovementAnimation {
     target: parent
     property: "rotation"
     running: true

     velocity: 20
     acceleration: 10
   }
 }

maxPropertyValue : variant

These properties limit the property value of the target to be within the [minPropertyValue maxPropertyValue] range. By default, they are not set and thus the property is modified by the velocity setting. The property type is either real or point.

You can use this property for example when modifying the position property: you can set borders with them, which the entity can not exceed. For example, the following code keeps the GameEntity inside the Scene:

 GameWindow {

   Scene {

     EntityBase {

       MovementAnimation {
         target: parent
         property: "pos"
         velocity: Qt.point(30, 10)
         running: true

         // limit the entity within the scene size
         minPropertyValue: scene.pos
         maxPropertyValue: Qt.point(scene.width, scene.height)
       }
     }
   }
 }

maxPropertyValueDifference : variant

This property holds the maximum difference the propertyValue can have within one time step. You can use it for example, to prevent the rotation exceeding a maximum rotation value. This value might come from the MoveToPointHelper component, which provides the exact rotation towards a target point.

Consider this example, where the followerEntity rotates towards the targetPoint, and does not over-rotate thanks to the maxPropertyValueDifference setting:

 GameEntity {
   id: followerEntity

   MoveToPointHelper {
     id: moveToPointHelper
     // the target point the follerEntity should rotate to
     // its rotation will then be 45 degrees, because it starts at position 0/0 with 0 rotation
     targetPoint: Qt.point(100, 100)
   }

   MovementAnimation {
     target: followerEntity
     property: "rotation"
     running: true
     velocity: 300*moveToPointHelper.outputXAxis

     // this avoids over-rotating, so rotating further than allowed
     maxPropertyValueDifference: moveToPointHelper.absoluteRotationDifference
   }
 }

See also MoveToPointHelper::outputXAxis.


maxVelocity : variant

These properties limit the velocity value to be within the [minVelocity maxVelocity] range. By default, they are not set and thus the velocity can change freely. The property type is either real or point.


minPropertyValue : variant

These properties limit the property value of the target to be within the [minPropertyValue maxPropertyValue] range. By default, they are not set and thus the property is modified by the velocity setting. The property type is either real or point.

You can use this property for example when modifying the position property: you can set borders with them, which the entity can not exceed. For example, the following code keeps the GameEntity inside the Scene:

 GameWindow {

   Scene {

     EntityBase {

       MovementAnimation {
         target: parent
         property: "pos"
         velocity: Qt.point(30, 10)
         running: true

         // limit the entity within the scene size
         minPropertyValue: scene.pos
         maxPropertyValue: Qt.point(scene.width, scene.height)
       }
     }
   }
 }

minVelocity : variant

These properties limit the velocity value to be within the [minVelocity maxVelocity] range. By default, they are not set and thus the velocity can change freely. The property type is either real or point.


property : string

This string defines the property of the target that should be animated. For example, it can be set to x, y, rotation, or pos (when the position should be animated).

The other properties including velocity or acceleration, must be the same type like this property. So when the property is set to "x", the velocity must be of type real. When it is set to "pos", the type must be point.


running : bool

This property holds whether the animation is running. By default, animations are not running.

This is an example of an animation that is toggled with every mouse click:

 Scene {

   MouseArea {
     anchors.fill: parent

     // toggles the running property
     // the velocity does not have with the value 40 when toggled, but it has the last value when running changed to false
     onClicked: movementAnimation.running = !movementAnimation.running
   }

   EntityBase {

     MovementAnimation {
       id: movementAnimation
       target: parent
       property: "x"
       velocity: 40
     }
   }
 }

target : Object

The target object whose property should be animated.


velocity : variant

The speed how much the property changes per second. Can either be of type real or point (when the position should be modified).

If the velocity is set to 10 for example, and the initial rotation is set to 50, it will be 60 after one second. Here is the source code for this example:

 Item {
   rotation: 50

   MovementAnimation {
     target: parent
     property: "rotation"
     velocity: 10
     running: true
   }
 }

Signal Documentation

limitReached()

This handler is called when minPropertyValue or maxPropertyValue was reached. In case the minPropertyValue or maxPropertyValue are of type point, the handler is called when either x or y is reaching its borders. The signal will be emitted until the boundaries or the target property have been reset. In wrapping mode it is called just before the target property is set to the new min/max value. It can be used for looping the movement manually, for instance, an endless background can be created using the signal by setting a new max value when the signal is reached.


started()

This handler is called when start() was called or running changed from false tu true.


stopped()

This handler is called when stop() was called or running changed from true to false.


Method Documentation

void start()

Call this function to start the animation.

If the animation is already running, calling this method has no effect. The running property will be true following a call to start().

When started, the last velocity value will be used. If you want to reset the velocity to the value at first start, you must reset it manually be changing the velocity property.

See also started and running.


void stop()

Call this function to stop the animation.

If the animation is not running, calling this method has no effect. The running property will be false following a call to stop().

The velocity value is not changed automatically after a call to stop.

See also stopped and running.


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
Sign up for Free and start developing right away!
I want to make Games
I want to make Apps
Game Development
Cross-Platform, Any Resolution

Use one IDE to deploy to all supported platforms, including iOS and Android, from a single code base.

Support all screen resolutions, aspect ratios and sizes with auto-adapting UI elements, smart scene scaling and memory efficient asset selection.

Learn More

V-Play ranked #1 at research2guidance cross-platform tool benchmarking 2014 by 2188 developers comparing 40 leading tools.

Multiplayer

V-Play Multiplayer supports both real-time and turn-based gameplay, so you can use it to make many different types of cross-platform multiplayer games. It's perfect for making player-vs-player games like 'Words with Friends' or games for a large amount of players, such as 'Clash of Clans'.

Learn More Video

Highscores & Achievements

The V-Play Game Network is a cross-platform gaming service that allows players around the world to compare game highscores and achievements. Players can also challenge each other across multiple platforms and share their progress on Facebook.

Learn More

QML & JavaScript

Qt Meta Language is a highly intuitive reactive language, which is super easy to learn, yet it's extremely powerful and flexible. Mix it with JavaScript to create awesome stuff, with just a few lines of code.

import QtQuick 2.0
import VPlay 2.0

GameWindow {
  Scene {
    
    SimpleButton {
      anchors.centerIn: parent
      text: "Press Me"
      onClicked: {
        console.debug("Wow you pressed me!")
      }
    }
  }
}

Learn More

Monetize & Analyze

With V-Play, you can use many 3rd party services for ads, in-app purchases, analytics and more, with just a few lines of code. All of these plugins work cross-platform, which allows you to maintain a single code base.

Learn More

Level Editor

The LevelEditor can be used during development to create and modify levels for your game, which you can then bundle in your final publishing build. Additionally, you can also integrate the in-game level editor to your published game and let your gamers create new levels.

Learn More Video

Card Game like UNO, Hearthstone or Poker

We got a demo game for you!

The V-Play SDK includes an open-source demo for this game genre. You can use its source code and build your game in record time. After installing V-Play, you can simply open the .pro file with Qt Creator, the development environment used for V-Play.

<Path to V-PlaySDK>/Examples/V-Play/demos/OneCard/OneCard.pro

Match-3 like Candy Crush Saga

We got a demo game for you!

The V-Play SDK includes an open-source demo for this game genre. You can use its source code and build your game in record time. After installing V-Play, you can simply open the .pro file with Qt Creator, the development environment used for V-Play.

<Path to V-PlaySDK>/Examples/V-Play/demos/JuicySquash/JuicySquash.pro

<Path to V-PlaySDK>/Examples/V-Play/demos/JuicySquashAdvanced/JuicySquashAdvanced.pro

Puzzle like 2048 or Threes!

We got a demo game for you!

The V-Play SDK includes an open-source demo for this game genre. You can use its source code and build your game in record time. After installing V-Play, you can simply open the .pro file with Qt Creator, the development environment used for V-Play.

<Path to V-PlaySDK>/Examples/V-Play/demos/2048/2048.pro

Casino like Big Win Slots

We got a demo game for you!

The V-Play SDK includes an open-source demo for this game genre. You can use its source code and build your game in record time. After installing V-Play, you can simply open the .pro file with Qt Creator, the development environment used for V-Play.

<Path to V-PlaySDK>/Examples/V-Play/demos/FlaskOfRum/FlaskOfRum.pro

Side Scroller like Jetpack Joyride or Flappy Bird

We got a demo game for you!

The V-Play SDK includes an open-source demo for this game genre. You can use its source code and build your game in record time. After installing V-Play, you can simply open the .pro file with Qt Creator, the development environment used for V-Play.

<Path to V-PlaySDK>/Examples/V-Play/demos/FlappyBird/FlappyBird.pro

Tower Defense like Castle Defense or Bloons TD

We got a demo game for you!

The V-Play SDK includes an open-source demo for this game genre. You can use its source code and build your game in record time. After installing V-Play, you can simply open the .pro file with Qt Creator, the development environment used for V-Play.

<Path to V-PlaySDK>/Examples/V-Play/demos/Squaby/Squaby.pro

Falldown & Jump like Doodle Jump or Mega Jump

We got a demo game for you!

The V-Play SDK includes an open-source demo for this game genre. You can use its source code and build your game in record time. After installing V-Play, you can simply open the .pro file with Qt Creator, the development environment used for V-Play.

<Path to V-PlaySDK>/Examples/V-Play/demos/ChickenOutbreak/ChickenOutbreak.pro

<Path to V-PlaySDK>/Examples/V-Play/demos/ChickenOutbreak2/ChickenOutbreak2.pro

<Path to V-PlaySDK>/Examples/V-Play/demos/DoodleJump/DoodleJump.pro

Platformer like Super Mario or Lep's World

We got a demo game for you!

The V-Play SDK includes an open-source demo for this game genre. You can use its source code and build your game in record time. After installing V-Play, you can simply open the .pro file with Qt Creator, the development environment used for V-Play.

<Path to V-PlaySDK>/Examples/V-Play/demos/Platformer/Platformer.pro

<Path to V-PlaySDK>/Examples/V-Play/demos/PlatformerWithLevelEditor/PlatformerWithLevelEditor.pro

Action like Angry Birds, Fruit Ninja, Cut the Rope

We got a demo game for you!

The V-Play SDK includes an open-source demo for this game genre. You can use its source code and build your game in record time. After installing V-Play, you can simply open the .pro file with Qt Creator, the development environment used for V-Play.

<Path to V-PlaySDK>/Examples/V-Play/demos/StackTheBoxWithCommunityEditor/StackTheBoxWithCommunityEditor.pro

<Path to V-PlaySDK>/Examples/V-Play/demos/BalloonPop/BalloonPop.pro

<Path to V-PlaySDK>/Examples/V-Play/demos/CarChallenge/CarChallenge.pro

Arcade like Arkanoid or Space Invaders

We got a demo game for you!

The V-Play SDK includes an open-source demo for this game genre. You can use its source code and build your game in record time. After installing V-Play, you can simply open the .pro file with Qt Creator, the development environment used for V-Play.

<Path to V-PlaySDK>/Examples/V-Play/demos/ZombieBreak/ZombieBreak.pro

Community like Super Mario Maker or Minecraft

We got a demo game for you!

The V-Play SDK includes an open-source demo for this game genre. You can use its source code and build your game in record time. After installing V-Play, you can simply open the .pro file with Qt Creator, the development environment used for V-Play.

<Path to V-PlaySDK>/examples/Squaby/Squaby.pro

<Path to V-PlaySDK>/Examples/V-Play/demos/StackTheBoxWithCommunityEditor/StackTheBoxWithCommunityEditor.pro

<Path to V-PlaySDK>/Examples/V-Play/demos/PlatformerWithLevelEditor/PlatformerWithLevelEditor.pro

Any other Idea? let us know how we can help you

You are looking for another demo?

The V-Play SDK includes many open-source demos for different game genres. You can use their source code and build your game in record time. After installing V-Play, you can simply open the .pro file with Qt Creator, the development environment used for V-Play.

If you do not find your game genre in this list and wonder if V-Play is the right choice, just contact us, we are happy to help!

Contact Us

App Development
Better Apps, Less Effort

Develop feature-rich, cross-platform mobile apps from a single code base.

V-Play apps look, feel and perform exactly like native iOS, Android and Desktop apps. With less code & much faster development time.

Learn More Highlights Video

V-Play ranked #1 at research2guidance cross-platform tool benchmarking 2014 by 2188 developers comparing 40 leading tools.

Save Time, Code & Money

Save up to 90% source code with V-Play, compared to frameworks like Xamarin, Titanium, React Native and others.

Learn More

QML & JavaScript

Qt Meta Language is a highly intuitive reactive language, which is super easy to learn, yet it's extremely powerful and flexible. Mix it with JavaScript to create awesome stuff, with just a few lines of code. QML also allows you to easily create smooth and complex animations.

import QtQuick 2.0
import VPlayApps 2.0

App {
  Page {
    
    AppButton {
      anchors.centerIn: parent
      text: "Press Me"
      onClicked: {
        console.debug("Wow you pressed me!")
      }
    }
  }
}

Learn More

Monetize & Analyze

With V-Play, you can use many 3rd party services for ads, in-app purchases, analytics and more, with just a few lines of code. All of these plugins work cross-platform, which allows you to maintain a single code base.

Learn More

Native Sensors & More

V-Play Apps harness the power of Qt, the leading cross-platform development framework used by over 1,000,000 developers.

This gives your access to native device features like sensors, camera, file system as well as multimedia, networking, localization and much more.

Learn More

Responsive Design

V-Play has built in responsive design capabilities, you can target phones and tablets with the same source code.

Learn More

Highly Extensible

You have existing JavaScript, C++ or native code? You want to add any 3rd party SDK that we do not offer already?

No worries, you can add any JS, C++, Java or Objective-C code to your project.

Learn More

Component Showcase App shows the most important V-Play features and components

We got a demo app for you!

The V-Play SDK includes an open-source demo for this app type. You can use its source code and build your app in record time. After installing V-Play, you can simply open the .pro file with Qt Creator, the development environment used for V-Play.

<Path to V-PlaySDK>/Examples/V-Play/appdemos/showcase/Showcase.pro

Qt World Summit Conference App a full-featured conference management app made by V-Play

We got a demo app for you!

The V-Play SDK includes an open-source demo for this app type. You can use its source code and build your app in record time. After installing V-Play, you can simply open the .pro file with Qt Creator, the development environment used for V-Play.

<Path to V-PlaySDK>/Examples/V-Play/appdemos/qtws2016/QtWS2016.pro

Twitter App how to build layouts like in the official Twitter app for iOS and Android

We got a demo app for you!

The V-Play SDK includes an open-source demo for this app type. You can use its source code and build your app in record time. After installing V-Play, you can simply open the .pro file with Qt Creator, the development environment used for V-Play.

<Path to V-PlaySDK>/Examples/V-Play/appdemos/twitter/Twitter.pro

Maps App displays free bikes or boxes at bike stations for Vienna's bike sharing service Citybike Wien

We got a demo app for you!

The V-Play SDK includes an open-source demo for this app type. You can use its source code and build your app in record time. After installing V-Play, you can simply open the .pro file with Qt Creator, the development environment used for V-Play.

<Path to V-PlaySDK>/Examples/V-Play/appdemos/maps/Maps.pro

Messaging App demonstrates how to create the UI of a Facebook Messenger like app

We got a demo app for you!

The V-Play SDK includes an open-source demo for this app type. You can use its source code and build your app in record time. After installing V-Play, you can simply open the .pro file with Qt Creator, the development environment used for V-Play.

<Path to V-PlaySDK>/Examples/V-Play/appdemos/messaging/Messaging.pro

Weather App how to include powerful animations into your user interface

We got a demo app for you!

The V-Play SDK includes an open-source demo for this app type. You can use its source code and build your app in record time. After installing V-Play, you can simply open the .pro file with Qt Creator, the development environment used for V-Play.

<Path to V-PlaySDK>/Examples/V-Play/appdemos/waether/Weather.pro

Any other Idea? let us know how we can help you

You are looking for another app demo?

The V-Play SDK includes many open-source demos for different app types. You can use their source code and build your app in record time. After installing V-Play, you can simply open the .pro file with Qt Creator, the development environment used for V-Play..

If you do not find your app type in this list and wonder if V-Play is the right choice, just contact us, we are happy to help!

Contact Us