ColliderBase

The Base component for BoxCollider, CircleCollider and PolygonCollider. All physics colliders including BoxCollider, CircleCollider and PolygonCollider inherit from ColliderBase. More...

Import Statement: import VPlay 2.0
Inherited By:

BoxCollider, CircleCollider, and PolygonCollider.

Properties

Methods

Detailed Description

It is a convenience component for a physics Body with support for forwarding the position change of the physics body to the contained entity. But it also forwards the position change of the entity to the physics system, if collisionTestingOnlyMode is set to true. See Type of Games Using Physics for an explanation of these 2 type of games.

The derived components need to overwrite the fixtures property and add the fixture(s) that define the physics shape. The most common components include a single Box, Circle or Polygon fixture, for which there already exist corresponding V-Play components BoxCollider, CircleCollider and PolygonCollider.

If you need more complex fixtures, inherit from the ColliderBase.

Example Usage

The CircleCollider for example is implemented like the following:

import VPlay 2.0

ColliderBase {
  id: collider
  objectName: "circleCollider"

  property alias fixture: fixture
  property alias friction: fixture.friction
  property alias restitution: fixture.restitution
  property alias density: fixture.density
  property alias categories: fixture.categories
  property alias collidesWith: fixture.collidesWith
  property alias sensor: fixture.sensor
  property alias groupIndex: fixture.groupIndex
  property alias radius: fixture.radius

  fixtures: Circle {
    id: fixture

    x: collider.x
    y: collider.y
    sensor: collisionTestingOnlyMode
  }
}

Property Documentation

active : bool

This property holds whether the physics Body is active, i.e. if it is affected by the physics simulation.

This property is connected to the EntityBase::collidersActive property, which is by default true. If you set it to true, but the collidersActive property is false, this collider will still be inactive!

See also Body::active.


angularDamping : real

This property holds the damping of linearVelocity. Damping is used to reduce the world velocity of bodies. Damping is different than friction because friction only occurs with contact. Damping is not a replacement for friction and the two effects should be used together.

Damping parameters should be between 0 and infinity, with 0 meaning no damping, and infinity meaning full damping. Normally you will use a damping value between 0 and 0.1.

The default value is 0.

See also angularVelocity and linearDamping.


angularVelocity : real

This property holds the angular speed of the body at the center of mass in radians/second.

See also Body::angularVelocity.


body : Body

This property alias allows access to the physics Body of this component.

Usually, you will not directly need to access this property, because you can access all body properties by the provided alias properties.

It can be used to convert vectors and points between world and local coordinates with toWorldVector(), toWorldPoint(), toLocalVector() and toLocalPoint() methods.


bodyType : BodyType

Set this property to either Body.Static, Body.Dynamic or Body.Kinetic. The is required so the Body enum is known.

Use the Static type for non-moving objects. Note that only dynamic bodies can collide with each other.

By default, bodyType is set to Body.Dynamic.

See also Body::bodyType.


bullet : bool

Set this flag to true for a very fast moving, small body that may tunnel through other bodies.

The default value is false.

See also Body::bullet.


collisionTestingOnlyMode : bool

Set this property to false when the position & rotation should be updated by Box2D (the default value). When you set it to true, the positions are taken from the target and the colliders are only used for collision detection but not for position updating.

The target is set to the owningEntity in the ColliderBase, so any position update of the entity gets forwarded to the physics system. So when you set it to true, the entity position gets modified from other components like MoveToPointHelper or NumberAnimation).

If you set this property to true, the fixture in the derived collider classes BoxCollider, CircleCollider and PolygonCollider get set their Fixture::isSensor flag to true and sleepingAllowed to false. Otherwise no position updating would be possible.

By default, this property is set to false.

See also Body::collisionTestingOnlyMode.


fixedRotation : bool

Set this property to true if you do not want the body to rotate. The default value is false, so the body can freely rotate.

See also Body::fixedRotation.


fixtures : list<Fixture>

Use this property to add fixtures in your derived components. Only set this property when directly creating from ColliderBase, and not when using BoxCollider, CircleCollider or PolygonCollider.

Here is an example:

ColliderBase {
  fixtures: Circle {
    id: fixture

    x: collider.x
    y: collider.y
    sensor: collisionTestingOnlyMode
  }
}

See also Body::fixtures.


force : point

If you set this property, this force is applied continuously every frame from the center of the body. The force is set in kg*pixels/s^2 and is 0 by default.

It is a convenience function for applying forces, which should usually be done over a longer time period. So instead of setting up a Timer object and call applyForce() in there, you can set this property to anything non-zero and it is applied automatically.

If you want to apply a force from an origin point that is not the body center, you can use applyForce(). An applied force from no center has the effect of the object being rotated. Except if the fixedRotation property is set.

Note: A force is only applied when the bodyType is not set to Body.Static. Applying the force wakes up the body, so awake gets set to true if it was false before.

See also Body::force and Body::applyForce().


gravityScale : real

Scales the gravity defined in the PhysicsWorld before being applied to this body. A scale of 0 would mean this body is not affected by gravity.

The default value is 1.0, so the defined gravity is unchanged.

See also Body::gravityScale.


linearDamping : real

This property holds the damping of linearVelocity. Damping is used to reduce the world velocity of bodies. Damping is different than friction because friction only occurs with contact. Damping is not a replacement for friction and the two effects should be used together.

Damping parameters should be between 0 and infinity, with 0 meaning no damping, and infinity meaning full damping. Normally you will use a damping value between 0 and 0.1.

The default value is 0.

See also linearVelocity and angularDamping.


linearVelocity : point

The linearVelocity holds the current speed in x and y direction of the physics body at the center of mass in local coordinates in pixels/second.

If you want to retrieve the world coordinates of the current velocity, use Body::toWorldVector(linearVelocity).

You can also calculate the rotation of a local linearVelocity by using Math::atan2(). Consider this example: MyGameBuildEntityButton.qml:

// get the current local forward vector
var localForward = linearVelocity;
// mirror the current velocity horizontally
localForward.x *= -1;
// calculate the new angle of the mirrored direction
var newAngle = Math.atan2(localForward.y, localForward.x);
// set the mirrored angle to the entity AND to the collider, as the rotation of the entity is not automatically forwarded because collisionTestingOnlyMode is set to false
entity.rotation = newAngle;
collider.rotation = newAngle;

See also Body::linearVelocity.


sleeping : bool

Read this this flag to know if this physics body with bodyType Body.Dynamic or Body.Kinetic is sleeping.

This is a read-only property and only for detecting if the body is sleeping - to control if sleeping is allowed use sleepingAllowed.

See also sleepingAllowed and Body::bodyType.


sleepingAllowed : bool

This property holds whether the body is allowed to get inactive for performance optimizations. The default value is the inverse of collisionTestingOnlyMode, so sleepingAllowed: !collisionTestingOnlyMode. This is needed to avoid sleeping when the collider gets used for collision detection, because if no forces or impulses are applied to the body it will sleep by default.

If collisionTestingOnlyMode is left at its default value (Which is false), this property has the default value true.

See also Body::sleepingAllowed.


torque : real

If you set this property, this torque is applied continuously every frame. This affects the angular velocity without affecting the linear velocity. The torque is in kg*degrees/second^2 and is 0 by default.

This is a convenience function for applying torques, which should usually be done over a longer time period. So instead of setting up a Timer object and call applyTorque() in there, you can set this property to anything non-zero and it is applied automatically.

Note: A torque is only applied when the bodyType is not set to Body.Static. Applying the torque wakes up the body, so active gets set to true if it was false before.

See also Body::torque and Body::applyTorque().


Method Documentation

applyLinearImpulse( impulseVector, worldPoint)

Applies an impulse with the direction of impulseVector at the worldPoint of the physics Body. The impulseVector is in world coordinates, so if you want to apply the impulse based on the current body rotation use Body::toWorldVector().

Consider this example:

BoxCollider {
  id: collider

  MouseArea {
    anchors.fill: parent

    onClicked: {
      var forwardVectorInBody = collider.body.toWorldVector(Qt.point(10, 0));

      // apply the impulse from the world center, in the direction of movement
      collider.applyLinearImpulse(forwardVectorInBody, collider.body.getWorldCenter());
    }
  }

}

You can apply an impulse to let the physics object immediately react to it. So the difference to the Body::applyForce() function is, that a force is applied steadily, while an impulse is only a single shot.


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