Box2D Examples
import QtQuick 2.0
import Felgo 4.0
GameWindow {
id: gameWindow
activeScene: scene
Timer {
running: true
repeat: true
interval: 1000
onTriggered: {
var ballId = entityManager.createEntityFromUrlWithProperties(
Qt.resolvedUrl("Ball.qml"),
{
x: Math.random() * (world.width-40) + 20,
y: -100
})
}
}
MouseArea {
anchors.fill: parent
onClicked: {
if(prismaticJoint.motorSpeed === 0)
prismaticJoint.motorSpeed = 320
prismaticJoint.motorSpeed *= -1
}
}
Scene {
id: scene
PhysicsWorld {
id: world
gravity.y: 20
updatesPerSecondForPhysics: 60
}
Square {
id: movingSquare
x: 50
y: 80
width: 60
height: 40
}
Square {
id: staticMiddleSquare
x: 240
y: 160
width: 80
height: 20
color: "red"
bodyType: Body.Static
}
PrismaticJoint {
id: prismaticJoint
lowerTranslation: -30
upperTranslation: 120
enableLimit: true
maxMotorForce: 3000
motorSpeed: 0
enableMotor: true
bodyA: staticMiddleSquare.body
bodyB: movingSquare.body
localAnchorA: Qt.point(staticMiddleSquare.width/2, staticMiddleSquare.height/2)
localAxisA: Qt.point(1, 0)
}
Wall {
id: ground
height: 20
anchors { left: parent.left; right: parent.right; top: parent.bottom }
}
Wall {
id: leftWall
width: 20
anchors { right: parent.left; bottom: ground.top; top: parent.top }
}
Wall {
id: rightWall
width: 20
anchors { left: parent.right; bottom: ground.top; top: parent.top }
}
Text {
z: 1
color: "white"
text: "Click on the screen to toggle the direction of the PrismaticJoint motor speed"
}
}
EntityManager {
id: entityManager
entityContainer: scene