Forums

OverviewV-Play 2 Support (Qt 5)physics acceleration object over time › Reply To: physics acceleration object over time

OverviewV-Play 2 Support (Qt 5)physics acceleration object over time › Reply To: physics acceleration object over time
#11334

Alex
V-Play Team

Hi,

and you are also using 1920 x 1080 as the size of your scene? Why are you not keeping the scene at a smaller logical size and use the scene scaling mechanism that V-Play has integrated instead? Box2D is made for physical simulations at a smaller scale, see this link to an example of a similar problem.

import VPlay 2.0
import QtQuick 2.0

GameWindow {
  id: gameWindow
  activeScene: scene
  width: 1920
  height: 1080

  EntityManager {
    id: entityManager
    entityContainer: scene
  }

  Component.onCompleted: {
    ball.collider.applyLinearImpulse(Qt.point(200,200), ball.collider.body.getWorldCenter());
  }

  Scene {
    id: scene
    width: 480 // this is a fourth of the gameWindow width
    height: 270 // this is a fourth of the gameWindow height
    // the scene will be scaled to fit into the gameWindow

    PhysicsWorld {

    }

    EntityBase {
      id: leftWall
      width: 10
      height: parent.height
      anchors.right: parent.left
      BoxCollider {
        anchors.fill: parent
        bodyType: Body.Static
      }
    }
    EntityBase {
      id: rightWall
      width: 10
      height: parent.height
      anchors.left: parent.right
      BoxCollider {
        anchors.fill: parent
        bodyType: Body.Static
      }
    }
    EntityBase {
      id: topWall
      width: parent.width
      height: 10
      anchors.bottom: parent.top
      BoxCollider {
        anchors.fill: parent
        bodyType: Body.Static
      }
    }
    EntityBase {
      id: bottomWall
      width: parent.width
      height: 10
      anchors.top: parent.bottom
      BoxCollider {
        anchors.fill: parent
        bodyType: Body.Static
      }
    }

    EntityBase {
      id: ball
      x: 50
      y: 50
      property alias collider: collider
      Rectangle {
        id: rect
        color: "#f00"
        width: 10
        height: 10
      }

      MovementAnimation {
        target: rect
        property: "rotation"
        velocity: collider.linearVelocity.x // this is the property binding to alter the rotation
        running: true
      }

      CircleCollider {
        id: collider
        radius: 5
        restitution: 1
        friction: 0
        bullet: true
        force: Qt.point(linearVelocity.x/10,linearVelocity.y/10)
        onLinearVelocityChanged: {
          console.debug("velocity " + linearVelocity.x + " | " + linearVelocity.y)
        }
      }
    }
  }
}

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