示例#1
0
 public boolean processGestureEvent(MTGestureEvent ge) {
   DragEvent de = (DragEvent) ge;
   try {
     Body body = (Body) comp.getUserData("box2d");
     MouseJoint mouseJoint;
     Vector3D to = new Vector3D(de.getTo());
     // Un-scale position from mt4j to box2d
     PhysicsHelper.scaleDown(to, scale);
     switch (de.getId()) {
       case DragEvent.GESTURE_STARTED:
         comp.sendToFront();
         body.wakeUp();
         body.setXForm(new Vec2(to.x, to.y), body.getAngle());
         mouseJoint = PhysicsHelper.createDragJoint(world, body, to.x, to.y);
         comp.setUserData(comp.getID(), mouseJoint);
         break;
       case DragEvent.GESTURE_UPDATED:
         mouseJoint = (MouseJoint) comp.getUserData(comp.getID());
         if (mouseJoint != null) {
           boolean onCorrectGameSide =
               ((MTComponent) de.getTarget()).containsPointGlobal(de.getTo());
           // System.out.println(((MTComponent)de.getTargetComponent()).getName()  + " Contains
           // " + to + " -> " + contains);
           if (onCorrectGameSide) {
             mouseJoint.setTarget(new Vec2(to.x, to.y));
           }
         }
         break;
       case DragEvent.GESTURE_ENDED:
         mouseJoint = (MouseJoint) comp.getUserData(comp.getID());
         if (mouseJoint != null) {
           comp.setUserData(comp.getID(), null);
           // Only destroy the joint if it isnt already (go through joint list and check)
           for (Joint joint = world.getJointList(); joint != null; joint = joint.getNext()) {
             JointType type = joint.getType();
             switch (type) {
               case MOUSE_JOINT:
                 MouseJoint mj = (MouseJoint) joint;
                 if (body.equals(mj.getBody1()) || body.equals(mj.getBody2())) {
                   if (mj.equals(mouseJoint)) {
                     world.destroyJoint(mj);
                   }
                 }
                 break;
               default:
                 break;
             }
           }
         }
         mouseJoint = null;
         break;
       default:
         break;
     }
   } catch (Exception e) {
     System.err.println(e.getMessage());
   }
   return false;
 }
示例#2
0
文件: Body.java 项目: rdo/speleo
 /**
  * Set the rotation of the body. This can only be called after the body has been added to the
  * world.
  *
  * @param rotation The new rotation of the body
  */
 public void setRotation(float rotation) {
   checkBody();
   jboxBody.setXForm(jboxBody.getPosition(), rotation);
 }
示例#3
0
文件: Body.java 项目: rdo/speleo
 /**
  * Set the position of the body. This can only be called after the body has been added to the
  * world.
  *
  * @param x The new x coordinate of the body
  * @param y The new y coordinate of the body
  */
 public void setPosition(float x, float y) {
   checkBody();
   jboxBody.setXForm(new Vec2(x, y), jboxBody.getAngle());
 }