Box2D Examples
import QtQuick 2.0
import Felgo 4.0
GameWindow {
id: screen
activeScene: scene
onKeyPressedGlobally: event => onKeysPressed(event)
function onKeysPressed(event) {
if (event.key === Qt.Key_Left) {
revolute.motorSpeed -= 5
console.debug("decreasing motor speed to", revolute.motorSpeed)
}
else if (event.key === Qt.Key_Right) {
revolute.motorSpeed += 5
console.debug("increasing motor speed to", revolute.motorSpeed)
}
}
Scene {
id: scene
PhysicsWorld {
id: world
debugDrawVisible: true
}
Wall {
id: ground
height: 20
anchors { left: parent.left; right: parent.right; top: parent.bottom }
}
Wall {
id: ceiling
height: 20
anchors { left: parent.left; right: parent.right; bottom: parent.top }
}
Wall {
id: leftWall
width: 20
anchors { right: parent.left; bottom: ground.top; top: ceiling.bottom }
}
Wall {
id: rightWall
width: 20
anchors { left: parent.right; bottom: ground.top; top: ceiling.bottom }
}
Square {
id: rod
x: world.width/2+middleBall.radius+15
y: world.height/2
width: 80
height: 20
}
Ball {
id: middleBall
x: world.width/2
y: world.height/2
radius: 20
}
RevoluteJoint {
id: revolute
maxMotorTorque: 300 * 32 * 32
motorSpeed: 0
bodyA: middleBall.body
bodyB: rod.body
enableMotor: true
localAnchorA: Qt.point(middleBall.radius, middleBall.radius)
localAnchorB: Qt.point(rod.width / 2 - 60, rod.height / 2)
}
Text {
z: 1
color: "white"
text: "Press left and right keys to change the RevoluteJoint motorSpeed"
}
}
EntityManager {
id: entityManager
}
MouseArea {
anchors.fill: parent