Package com.badlogic.gdx.physics.box2d

Examples of com.badlogic.gdx.physics.box2d.Body


    boxBodyDef.type = pBodyType;

    boxBodyDef.position.x = pCenterX / pPixelToMeterRatio;
    boxBodyDef.position.y = pCenterY / pPixelToMeterRatio;

    final Body boxBody = pPhysicsWorld.createBody(boxBodyDef);

    final PolygonShape boxPoly = new PolygonShape();

    final float halfWidth = pWidth * 0.5f / pPixelToMeterRatio;
    final float halfHeight = pHeight * 0.5f / pPixelToMeterRatio;

    boxPoly.setAsBox(halfWidth, halfHeight);
    pFixtureDef.shape = boxPoly;

    boxBody.createFixture(pFixtureDef);

    boxPoly.dispose();

    boxBody.setTransform(boxBody.getWorldCenter(), MathUtils.degToRad(pRotation));

    return boxBody;
  }
View Full Code Here


    circleBodyDef.position.x = pCenterX / pPixelToMeterRatio;
    circleBodyDef.position.y = pCenterY / pPixelToMeterRatio;

    circleBodyDef.angle = MathUtils.degToRad(pRotation);

    final Body circleBody = pPhysicsWorld.createBody(circleBodyDef);

    final CircleShape circlePoly = new CircleShape();
    pFixtureDef.shape = circlePoly;

    final float radius = pRadius / pPixelToMeterRatio;
    circlePoly.setRadius(radius);

    circleBody.createFixture(pFixtureDef);

    circlePoly.dispose();

    return circleBody;
  }
View Full Code Here

  public static Body createLineBody(final PhysicsWorld pPhysicsWorld, final float pX1, final float pY1, final float pX2, final float pY2, final FixtureDef pFixtureDef, final float pPixelToMeterRatio) {
    final BodyDef lineBodyDef = new BodyDef();
    lineBodyDef.type = BodyType.StaticBody;
   
    final Body boxBody = pPhysicsWorld.createBody(lineBodyDef);
   
    final PolygonShape linePoly = new PolygonShape();
   
    linePoly.setAsEdge(new Vector2(pX1 / pPixelToMeterRatio, pY1 / pPixelToMeterRatio), new Vector2(pX2 / pPixelToMeterRatio, pY2 / pPixelToMeterRatio));
    pFixtureDef.shape = linePoly;
   
    boxBody.createFixture(pFixtureDef);
   
    linePoly.dispose();
   
    return boxBody;
  }
View Full Code Here

    final float[] sceneCenterCoordinates = pShape.getSceneCenterCoordinates();
    boxBodyDef.position.x = sceneCenterCoordinates[Constants.VERTEX_INDEX_X] / pPixelToMeterRatio;
    boxBodyDef.position.y = sceneCenterCoordinates[Constants.VERTEX_INDEX_Y] / pPixelToMeterRatio;

    final Body boxBody = pPhysicsWorld.createBody(boxBodyDef);

    final PolygonShape boxPoly = new PolygonShape();

    boxPoly.set(pVertices);
    pFixtureDef.shape = boxPoly;

    boxBody.createFixture(pFixtureDef);

    boxPoly.dispose();

    return boxBody;
  }
View Full Code Here

    final float[] sceneCenterCoordinates = pShape.getSceneCenterCoordinates();
    boxBodyDef.position.x = sceneCenterCoordinates[Constants.VERTEX_INDEX_X] / pPixelToMeterRatio;
    boxBodyDef.position.y = sceneCenterCoordinates[Constants.VERTEX_INDEX_Y] / pPixelToMeterRatio;

    final Body boxBody = pPhysicsWorld.createBody(boxBodyDef);

    final int vertexCount = pTriangleVertices.size();
    for(int i = 0; i < vertexCount; /* */) {
      final PolygonShape boxPoly = new PolygonShape();

      TMP_TRIANGLE[2] = pTriangleVertices.get(i++);
      TMP_TRIANGLE[1] = pTriangleVertices.get(i++);
      TMP_TRIANGLE[0] = pTriangleVertices.get(i++);

      boxPoly.set(TMP_TRIANGLE);
      pFixtureDef.shape = boxPoly;

      boxBody.createFixture(pFixtureDef);

      boxPoly.dispose();
    }

    return boxBody;
View Full Code Here

  // ===========================================================

  @Override
  public void onUpdate(final float pSecondsElapsed) {
    final IShape shape = this.mShape;
    final Body body = this.mBody;

    if(this.mUpdatePosition) {
      final Vector2 position = body.getPosition();
      final float pixelToMeterRatio = this.mPixelToMeterRatio;
      shape.setPosition(position.x * pixelToMeterRatio - this.mShapeHalfBaseWidth, position.y * pixelToMeterRatio - this.mShapeHalfBaseHeight);
    }

    if(this.mUpdateRotation) {
      final float angle = body.getAngle();
      shape.setRotation(MathUtils.radToDeg(angle));
    }
  }
View Full Code Here

    batch.begin();
    {
      batch.draw(bg, -viewportWidth / 2f, 0, viewportWidth, viewportHeight);
      batch.enableBlending();
      for (int i = 0; i < BALLSNUM; i++) {
        Body ball = balls.get(i);
        Vector2 position = ball.getPosition();
        float angle = MathUtils.radiansToDegrees * ball.getAngle();
        batch.draw(
            textureRegion,
            position.x - RADIUS, position.y - RADIUS,
            RADIUS, RADIUS,
            RADIUS * 2, RADIUS * 2,
 
View Full Code Here

    for (int i = 0; i < BALLSNUM; i++) {
      // Create the BodyDef, set a random position above the
      // ground and create a new body
      boxBodyDef.position.x = -20 + (float) (Math.random() * 40);
      boxBodyDef.position.y = 10 + (float) (Math.random() * 15);
      Body boxBody = world.createBody(boxBodyDef);
      boxBody.createFixture(def);
      balls.add(boxBody);
    }
    ballShape.dispose();
  }
View Full Code Here

                   
                    if("true".equals(collision)){
                        BodyDef bodyDef = new BodyDef();
                        bodyDef.type = BodyDef.BodyType.StaticBody;
                        bodyDef.position.set(Detonator.WORLD_TO_BOX2D*((x*Terrain.tileWidth)-(Terrain.tileWidth / 2)), Detonator.WORLD_TO_BOX2D*(y*Terrain.tileHeight));
                        Body boxBody = map.world.createBody(bodyDef);
                        CircleShape circle = new CircleShape();
                        circle.setRadius(Detonator.WORLD_TO_BOX2D*8);
                        boxBody.createFixture(new CircleShape(),0.5f);
                       
                        Log.info("COLLIDES, map coords: "+Detonator.WORLD_TO_BOX2D*((x*Terrain.tileWidth)-(Terrain.tileWidth / 2))+":"+Detonator.WORLD_TO_BOX2D*(y*Terrain.tileHeight));
                       
                    }
                }
View Full Code Here

    boxBodyDef.position.x = x;
    boxBodyDef.position.y = y;
    boxBodyDef.angle = angle;
    boxBodyDef.angularDamping = 1f;
    boxBodyDef.linearDamping = 1.0f;
    Body boxBody = world.createBody(boxBodyDef);

    boxBody.createFixture(boxPoly, 1);
    // add the box to our list of boxes
    body = boxBody;
   
    body.setUserData(this);
   
View Full Code Here

TOP

Related Classes of com.badlogic.gdx.physics.box2d.Body

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.