Forums

OverviewV-Play 1 SupportDetecting application state › Reply To: Detecting application state

OverviewV-Play 1 SupportDetecting application state › Reply To: Detecting application state
#5763

Alex
V-Play Team

In our next daily build we will introduce a new property to the PhysicsWorld, called timeScale. This will allow you to slow down and speed up time of the physics world.
Here is some demo source code, showing how you will be able to use the property. Stay tuned!

import VPlay 1.0
import Box2D 1.0
import QtQuick 1.1

GameWindow {
  id: window
  width: 960
  height: 640

  EntityManager {
    id: entityManager
  }

  Scene {
    id: scene
    width: 960
    height: 640
    Column {
      SimpleButton {
        text: world.running === true ? "pause" : "resume"
        onClicked: {
          world.running = !world.running
        }
      }
      SimpleButton {
        text: "normal"
        onClicked: {
          world.timeScale = 1
        }
      }
      SimpleButton {
        text: "slower"
        onClicked: {
          world.timeScale = 0.2
        }
      }
      SimpleButton {
        text: "faster"
        onClicked: {
          world.timeScale = 2
        }
      }
    }

    PhysicsWorld {
      id: world
      gravity.y: -10
      updatesPerSecondForPhysics: 60
      // you can fade changes of timeScale smoothly to achieve an even nicer effect
      Behavior on timeScale {
        NumberAnimation { duration: 500 }
      }
    }

    EntityBase {
      width: parent.width
      height: 20
      anchors.bottom: parent.bottom
      BoxCollider {
        anchors.fill: parent
        bodyType: Body.Static
        categories: Box.Category1
        Rectangle {
          color: "green"
          anchors.fill: parent
        }
      }
    }

    Repeater {
      model: 100
      EntityBase {
        id: entity
        x: 40 + Math.random()*800
        y: 200 + Math.random()*150
        width: 20
        height: 20
        BoxCollider {
          anchors.fill: parent
          friction: 0
          restitution: 1
          categories: Box.Category2
          collidesWith: Box.Category1
          Rectangle {
            color: "red"
            anchors.fill: parent
          }
        }
      }
    }
  }
}

Cheers,
Alex

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