World

Represents a Box2D physics world including bodies and joints. More...

Import Statement: import VPlay 2.0
Inherits:

QtObject

Inherited By:

PhysicsWorld

Properties

Signals

Methods

Detailed Description

This wraps the underlying Box2D b2World object as a QML type.

V-Play provides additional functionality in the PhysicsWorld component.

Property Documentation

autoClearForces : bool

If this is set to true, the forces applied to Bodies will be cleared every time step() with the clearForces() function.

The default value is true.


enableContactEvents : bool

If this is set to false, no contact events will be sent out by the physics engine.

The default value is true.


gravity : point

This property holds the x and y gravity of the PhysicsWorld in meters/second^2, which is the constant acceleration applied to all physics bodies.

The default gravity is {"x": 0, "y": 0}.

If you want to use earth gravity, set it to 0/9.81, for example with this code:

 PhysicsWorld {
   gravity.y: 9.81
 }

To make objects fall faster, increase the y value. Keep in mind, that also the applied forces should be adopted in case of a gravity change to have the same outcome.


pixelsPerMeter : real

Configures the conversion factor between QML units, pixels and Box2D units, meters.

Box2D uses meters as units for all distances, velocities, forces etc. In QML, pixels are used. In older version of V-Play, the scaling ratio between pixels and meters was fixed to 32 pixels / meter.

This ratio can be configured using the World::pixelsPerMeter property. It defaults to 32 so no change is needed for older games. This is useful to create more accurate physics simulation by specifying how big the simulated area on the screen would be in a real world. For example, if your game world should be 5 meters wide, and your Scene has a width of 480 logical pixels, this property should be set to 480 pixels / 5 meter = 96 pixels / meter.

This property affects the conversion of units between QML and Box2D for properties like sizes, distances, velocities, acceleration, forces, torques and densities. It also affects the mass of bodies, which gets calculated based on their fixture's dimensions in meters and their density.

The default value is 32 pixels/meter.


positionIterations : int

This property holds the number of position iterations used to process in one physics update step. Tune this variable for each game so it still looks good and set is as low as possible for best performance. Higher values cause the physics system to take longer, whereas lower values might cause unrealistic behaviors like merging colliders. Modify this value together with the PhysicsWorld::updatesPerSecondForPhysics property and the World::velocityIterations property.

By default, it is set to 5.

See also velocityIterations and PhysicsWorld::updatesPerSecondForPhysics.


profile : Profile

Returns profiling information about the state of the World which changes every time step().


running : bool

This property holds if the physics world is simulated. The default value is true. Set it to false when you would like to pause the game (e.g. when in the game menu).


timeStep : real

This determines the time length of one physics step. The step() function is then attempted to be called 1 / timeStep times per second. Note that it may be called less or more times based on current hardware workload, but the dt parameter will be adapted accordingly.

It gets normally automatically set to 1 / PhysicsWorld::updatesPerSecondForPhysics and does not need to be set manually.

See also PhysicsWorld::updatesPerSecondForPhysics.


velocityIterations : int

This property holds the number of velocity iterations used to process in one physics update step. Tune this variable for each game so it still looks good and set is as low as possible for best performance. Higher values cause the physics system to take longer, whereas lower values might cause unrealistic behaviors like merging colliders. Modify this value together with the PhysicsWorld::updatesPerSecondForPhysics property and the World::positionIterations property.

By default, it is set to 5.

See also positionIterations and PhysicsWorld::updatesPerSecondForPhysics.


Signal Documentation

postSolve(Contact contact)

Called after a contact event has been passed to the contact solver of the physics engine. It does not make sense to modify the contact parameter at this time.

See also preSolve.


preSolve(Contact contact)

Called before a contact event is passed to the contact solver of the physics engine. The parameter contact contains information about the contact event.

This can be used to completely disable a contact event and allow two bodies to temporarily pass through each other by setting contact.enabled to false. This can be useful if colliders change behavior, for example only letting objects pass through from one side, like in a platformer game:

 PhysicsWorld {
   id: physicsWorld
   gravity: Qt.point(0, 25)

   onPreSolve: {
     //this is called before the Box2DWorld handles contact events
     var entityA = contact.fixtureA.getBody().target
     var entityB = contact.fixtureB.getBody().target
     if(entityB.entityType === "platform" && entityA.entityType === "player" &&
         entityA.y + entityA.height > entityB.y) {
       //by setting enabled to false, they can be filtered out completely
       //-> disable cloud platform collisions when the player is below the platform
       contact.enabled = false
     }
   }
 }

Furthermore, other properties of the involved bodies and fixtures, like velocity, force, friction and restitution can be changed here before the contact gets handled.

See also postSolve.


stepped()

Called when a time step has been processed.


Method Documentation

Box2DBody bodyAt(point p)

Returns the Box2D Body at the given point p in world coordinates or null if there is no body at the given point or if the body is inactive.

Note: This function is slow as linear search is performed and should only be used if not many fixtures exist. It is also not guaranteed to find the top-most body, as the order is undefined! This function is blocking (so no callback involved), so use with care! Also note that only active bodies are considered.


void clearForces()

Clears all forces applied to all bodies.


void rayCast(RayCast rayCast, point from, point to)

Cast a ray from the point from to the point to and report fixtures in the ray's direction in RayCast::fixtureReported.


void step(real dt)

Manually perform a physics world time step with the given delta time. This is normally called 1 / timeStep times per second automatically.


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