Find the Best Demos and Examples

Check out this quick tour to find the best demos and examples for you, and to see how the Felgo SDK can help you to develop your next app or game!


OverviewFelgo 1 Support › Multi-touch for mouseJoint

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • #6355


    Is it possible to use multi-touch with mouseJoint? I need to swipe two balls in same time.


    Felgo Team


    I see no reason why it is not possible.

    You can take the Code from the StackTheBox demo game as a base, especially this part (i added some TODO comments about what i think needs to be added for your case):

        Component {
          id: mouseJoint
          MouseJoint {
            // make this high enough so the box with its density is moved quickly
            maxForce: window.maxForce
            // The damping ratio. 0 = no damping, 1 = critical damping. Default is 0.7
            dampingRatio: window.dampingRatio
            // The response speed, default is 5
            frequencyHz: window.frequencyHz
        // when the user presses a box, move it towards the touch position
        MouseArea {
          anchors.fill: parent
          // TODO add 2nd Body and MouseJoint property
          property Body selectedBody: null
          property MouseJoint mouseJointWhileDragging: null
          onPressed: {
            // TODO check if one of the joint properties is null (this is the case if only one or no ball is already being swiped)
            // if yes, create a new joint with the available (null) properties
            selectedBody = physicsWorld.bodyAt(Qt.point(mouseX, mouseY));
            console.debug("selected body at position", mouseX, mouseY, ":", selectedBody);
            // if the user selected a body, this if-check is true
            if(selectedBody) {
              // create a new mouseJoint
              mouseJointWhileDragging = mouseJoint.createObject(physicsWorld)
              // set the target position to the current touch position (initial position)
              mouseJointWhileDragging.targetPoint = Qt.point(mouseX, mouseY)
              // connect the joint with the body
              mouseJointWhileDragging.movingBody = selectedBody
              // set the physicsWorld where the joint should be created
     = physicsWorld
          onPositionChanged: {
            // TODO also add the 2nd joint
            // this check is necessary, because the user might also drag when no initial body was selected
            if (mouseJointWhileDragging)
              mouseJointWhileDragging.targetPoint = Qt.point(mouseX, mouseY)
          onReleased: {
            // TODO check which one of the bodies was released and destroy the corresponding joint
            // if the user pressed a body initially, remove the created MouseJoint
            if(selectedBody) {
              selectedBody = null
              if (mouseJointWhileDragging)

    I hope this helps you a little bit, let me know if you managed to make it work.





    Thank you very much for reply!

    We’ve tried this code, with two balls and MultiTouchArea instead of MouseArea. Unfortunately, we still have problem, when one ball is selected, second touch always change same ball position (we can select another ball only, when first touch was released). Is it possible to identify which touch was called for onPositionChanged event. Is there any properties like touchID ?

Viewing 3 posts - 1 through 3 (of 3 total)

RSS feed for this thread

You must be logged in to reply to this topic.