@Override public void render () { if (m_platform.getType() == BodyType.KinematicBody) { Vector2 p = m_platform.getTransform().getPosition(); Vector2 v = m_platform.getLinearVelocity(); if ((p.x < -10 && v.x < 0) || (p.x > 10 && v.x > 0)) { v.x = -v.x; m_platform.setLinearVelocity(v); } } super.render(); // if (renderer.batch != null) { // renderer.batch.begin(); // // renderer.batch.drawText(renderer.font, "Keys: (d) dynamic, (s) static, (k) kinematic", 0, Gdx.app.getGraphics() // // .getHeight(), Color.WHITE); // renderer.batch.end(); // } } }
protected void renderBody (Body body) { Transform transform = body.getTransform(); for (Fixture fixture : body.getFixtureList()) { if (drawBodies) { drawShape(fixture, transform, getColorByBody(body)); if (drawVelocities) { Vector2 position = body.getPosition(); drawSegment(position, body.getLinearVelocity().add(position), VELOCITY_COLOR); } } if (drawAABBs) { drawAABB(fixture, transform); } } }
private void drawJoint (Joint joint) { Body bodyA = joint.getBodyA(); Body bodyB = joint.getBodyB(); Transform xf1 = bodyA.getTransform(); Transform xf2 = bodyB.getTransform(); Vector2 x1 = xf1.getPosition(); Vector2 x2 = xf2.getPosition(); Vector2 p1 = joint.getAnchorA(); Vector2 p2 = joint.getAnchorB(); if (joint.getType() == JointType.DistanceJoint) { drawSegment(p1, p2, JOINT_COLOR); } else if (joint.getType() == JointType.PulleyJoint) { PulleyJoint pulley = (PulleyJoint)joint; Vector2 s1 = pulley.getGroundAnchorA(); Vector2 s2 = pulley.getGroundAnchorB(); drawSegment(s1, p1, JOINT_COLOR); drawSegment(s2, p2, JOINT_COLOR); drawSegment(s1, s2, JOINT_COLOR); } else if (joint.getType() == JointType.MouseJoint) { drawSegment(joint.getAnchorA(), joint.getAnchorB(), JOINT_COLOR); } else { drawSegment(x1, p1, JOINT_COLOR); drawSegment(p1, p2, JOINT_COLOR); drawSegment(x2, p2, JOINT_COLOR); } }
private void drawJoint (Joint joint) { Body bodyA = joint.getBodyA(); Body bodyB = joint.getBodyB(); Transform xf1 = bodyA.getTransform(); Transform xf2 = bodyB.getTransform(); Vector2 x1 = xf1.getPosition(); Vector2 x2 = xf2.getPosition(); Vector2 p1 = joint.getAnchorA(); Vector2 p2 = joint.getAnchorB(); if (joint.getType() == JointType.DistanceJoint) { drawSegment(p1, p2, JOINT_COLOR); } else if (joint.getType() == JointType.PulleyJoint) { PulleyJoint pulley = (PulleyJoint)joint; Vector2 s1 = pulley.getGroundAnchorA(); Vector2 s2 = pulley.getGroundAnchorB(); drawSegment(s1, p1, JOINT_COLOR); drawSegment(s2, p2, JOINT_COLOR); drawSegment(s1, s2, JOINT_COLOR); } else if (joint.getType() == JointType.MouseJoint) { drawSegment(joint.getAnchorA(), joint.getAnchorB(), JOINT_COLOR); } else { drawSegment(x1, p1, JOINT_COLOR); drawSegment(p1, p2, JOINT_COLOR); drawSegment(x2, p2, JOINT_COLOR); } }
protected void renderBody (Body body) { Transform transform = body.getTransform(); int len = body.getFixtureList().size; Array<Fixture> fixtures = body.getFixtureList(); for (int i = 0; i < len; i++) { Fixture fixture = fixtures.get(i); if (drawBodies) { if (body.isActive() == false && drawInactiveBodies) drawShape(fixture, transform, SHAPE_NOT_ACTIVE); else if (body.getType() == BodyType.StaticBody) drawShape(fixture, transform, SHAPE_STATIC); else if (body.getType() == BodyType.KinematicBody) drawShape(fixture, transform, SHAPE_KINEMATIC); else if (body.isAwake() == false) drawShape(fixture, transform, SHAPE_NOT_AWAKE); else drawShape(fixture, transform, SHAPE_AWAKE); } if (drawAABBs) { drawAABB(fixture, transform); } } }
public void interpolate(float alpha) { for (Box box : activeBoxes) { Body body = box.getBody(); if(body.isActive()) { Transform transform = body.getTransform(); Vector2 bodyPosition = transform.getPosition(); float bodyAngle = transform.getRotation(); box.x = bodyPosition.x * alpha + box.x * (1.0f - alpha); box.y = bodyPosition.y * alpha + box.y * (1.0f - alpha); box.angle = bodyAngle * alpha + box.angle * (1.0f - alpha); } } }
protected void renderBody (Body body) { Transform transform = body.getTransform(); for (Fixture fixture : body.getFixtureList()) { if (drawBodies) { drawShape(fixture, transform, getColorByBody(body)); if (drawVelocities) { Vector2 position = body.getPosition(); drawSegment(position, body.getLinearVelocity().add(position), VELOCITY_COLOR); } } if (drawAABBs) { drawAABB(fixture, transform); } } }
private void drawJoint (Joint joint) { Body bodyA = joint.getBodyA(); Body bodyB = joint.getBodyB(); Transform xf1 = bodyA.getTransform(); Transform xf2 = bodyB.getTransform(); Vector2 x1 = xf1.getPosition(); Vector2 x2 = xf2.getPosition(); Vector2 p1 = joint.getAnchorA(); Vector2 p2 = joint.getAnchorB(); if (joint.getType() == JointType.DistanceJoint) { drawSegment(p1, p2, JOINT_COLOR); } else if (joint.getType() == JointType.PulleyJoint) { PulleyJoint pulley = (PulleyJoint)joint; Vector2 s1 = pulley.getGroundAnchorA(); Vector2 s2 = pulley.getGroundAnchorB(); drawSegment(s1, p1, JOINT_COLOR); drawSegment(s2, p2, JOINT_COLOR); drawSegment(s1, s2, JOINT_COLOR); } else if (joint.getType() == JointType.MouseJoint) { drawSegment(joint.getAnchorA(), joint.getAnchorB(), JOINT_COLOR); } else { drawSegment(x1, p1, JOINT_COLOR); drawSegment(p1, p2, JOINT_COLOR); drawSegment(x2, p2, JOINT_COLOR); } }
Transform bodyTransform = box.getBody().getTransform(); Vector2 bodyPosition = bodyTransform.getPosition(); box.x = bodyPosition.x;