PathMovement

Interpolates an entity along a path and rotates it towards the target points. More...

Import Statement: import VPlay 2.0

Properties

Signals

Methods

Detailed Description

This component allows to move an object along waypoints of a path and automatically rotating towards the next waypoint. After the end of the path is reached, a pathCompleted() signal is emitted.

The required properties for the PathMovement are waypoints and velocity. The velocity defines with how many pixels per second the owningEntity moves. By default, the target of the position interpolations is the parent item, but it can be set manually with the property owningEntity. The completePathAnimationDuration gets calculated based on the waypoints and the defined velocity.

The entity is automatically rotated towards the next waypoint within rotationAnimation milliseconds. The rotation is not applied physically correct, i.e. the animated target will not move in the direction of its previous rotation, but it stays on the direct lines between the waypoints. If you want the animation behave realistically correct, you can use the MoveToPointHelper and a BoxCollider or CircleCollider. For such an example see the MoveToPointHelper::onTargetReached documentation.

You can start, stop and pause the path movement similar to normal Animation elements. Also looping is possible.

Example Usage

The following example moves the EntityBase along the waypoints. The entity moves with 100 px per second along each path line segment, and rotates towards the next waypoint within 200 milliseconds. After the last waypoint is reached, the entity is removed.

 import VPlay 2.0
 import QtQuick 2.0 // a QtQuick import is required for loops: Animation.Infinite

 EntityBase {
     id: entity

   PathMovement {
       velocity: 100
       rotationAnimationDuration: 200

       waypoints: [
         {x:0, y:0},
         {x:100, y:0},
         {x:100,  y:100},
         {x:0, y:100}
       ]

       onPathCompleted: {
           console.debug("last waypoint reached, destroy the entity");
           entity.removeEntity();
       }
   }
 }

You could also set the loops property to Animation.Infinite, to endlessly move along the waypoints. If loops is set, the entity is moved from the last waypoint to the first automatically.

As an alternative to the PathMovement, you could also use the QML PathView element. Its disadvantage is that you cannot rotate the entity towards the next waypoint. But it allows you to define different paths like Bezier curves.

Property Documentation

completePathAnimationDuration : int

This property holds the duration in milliseconds for the path movement from the first to the last waypoint. It is automatically calculated based on the velocity and the waypoints and is read-only.

If the PathMovement is set up like in the following example, the completePathDuration will be 1 second. Each of the 2 path segment is 50 px long, so with the velocity of 100 px per second, the result is 1 second.

 EntityBase {
     id: entity

   PathMovement {
       velocity: 100

       waypoints: [
         { x:0, y:0},
         { x:50, y:0},
         { x: 50, y: 50 }
       ]

       onPathCompleted: {
           console.debug("last waypoint reached, destroy the entity");
           entity.removeEntity();
       }
   }
 }

currentWaypointIndex : int

This read-only property holds the current index of the path waypoints. It starts with 0 when the owningEntity is in between the first and the second waypoint. When the second waypoint is reached, it gets set to 1 and so on.

When onPathCompleted() is called, the value is waypoints.length-1.


loops : int

This property holds the number of times the path movement will repeat from the first to the last waypoint.

By default, loops is 1: the path movement starts to interpolate from the first waypoint, and stops at the last waypoint.

If set to Animation.Infinite, the animation will continuously repeat until it is explicitly stopped - either by setting the running property to false, or by calling the stop() method.

If loops is set to anything else than the default value 1, the movement will interpolate from the last waypoint to the first.


paused : bool

This property holds whether the path movement interpolation is paused. By default, it is not paused.


rotationAnimationDuration : int

This property holds the duration how long it takes to rotate towards the next waypoint in ms. The default is 200.


rotationAnimationEnabled : bool

This property holds whether the rotation animation towards the next waypoint is applied. By default, it is true.


running : bool

This property holds whether the path movement interpolation is running. By default, the component will start with running set to true.


velocity : real

The pixels per second how fast the owningEntity moves along the path. If the velocity is set to 50 for example and the first waypoint is set to {x:50, y:0}, the waypoint will be reached after 1 second. If the first waypoint is set to {x:30, y:40}, the waypoint will also be reached after 1 second, because the distance from the origin point 0/0 to the first waypoint is 50 pixels.

The completePathAnimationDuration is automatically calculated based on the velocity and the waypoints. It is the sum of durations for each individual waypoint.

The default velocity is 100.


waypoints : variant

An array of waypoints of the path, which the owningEntity moves along. The entity moves straight from one point to the next, and gets rotated towards it within rotationAnimationDuration milliseconds.

The completePathAnimationDuration is calculated based on this property and the velocity - the longer the distance between the waypoints, the longer the duration will be.

Note: The position of the owningEntity is set to the first waypoint position.

This is an example of a rectangular movement, which will last 4 seconds to complete and then start from the beginning:

 EntityBase {

   PathMovement {
     velocity: 100
     loops: Animation.Infinite

     waypoints: [
       {x:0, y:0},
       {x:100, y:0},
       {x:100, y:100},
       {x:0, y:100}
       ]
   }
 }

You can also change the waypoints during the animation. In that case, the currently running path movement will be stopped if there is one running, and the movement starts with the first waypoint again.


Signal Documentation

pathCompleted()

This handler is called when the last waypoint of the path is reached. The position of owningEntity will be the position of the last waypoint.

When loops is set to Animation.Infinite, this will never be called. When loops is set to a value bigger than 1, this handler is only called once, not every time it reaches the first waypoint again.


waypointReached(int waypointIndex)

This handler is called when a waypoint with the index waypointIndex is reached.


Method Documentation

start()

Call this function to start the path movement.

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

See also running.


stop()

Call this function to stop the path movement.

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

See also 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