Forums

OverviewV-Play 1 SupportMulti-touch for mouseJoint › Reply To: Multi-touch for mouseJoint

OverviewV-Play 1 SupportMulti-touch for mouseJoint › Reply To: Multi-touch for mouseJoint
#6371

Alex
V-Play Team

Hi,

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
          mouseJointWhileDragging.world = 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)
            mouseJointWhileDragging.destroy()
        }
      }
    }

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

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