This is a very simple scene with box2d. I tried different viewports and different screen sizes. I could not figure out why the body drops very slow. Actually, I am not quite sure that it is slow, the reason is maybe the viewport settings etc. This is main class:
public class Main extends Game {
LevelScreen levelScreen;
@Override
public void create () {
levelScreen = new LevelScreen();
setScreen(levelScreen);
}
@Override
public void render () {
super.render();
}
}
And level screen:
public class LevelScreen extends Stage implements Screen {
private Batch batch;
private Camera camera;
private Texture ballTexture;
private Sprite ball;
private Viewport viewport;
//com
private Vector3 point = new Vector3();
private World world;
private Box2DDebugRenderer box2DDebugRenderer;
private CircleShape circleShape;
private FixtureDef fixtureDef;
private BodyDef bodyDef;
private Body circleBody;
private static final float SCENE_WIDTH = 1080;
private static final float SCENE_HEIGHT = 1920f;
public LevelScreen() {
super(new FitViewport(SCENE_WIDTH, SCENE_HEIGHT, new OrthographicCamera(SCENE_WIDTH, SCENE_HEIGHT)));
batch = getBatch();
camera = getCamera();
viewport = getViewport();
world = new World(new Vector2(0,-9.8f), true);
box2DDebugRenderer = new Box2DDebugRenderer();
bodyDef = new BodyDef();
bodyDef.type = BodyDef.BodyType.DynamicBody;
bodyDef.position.set(600, 1000);
ballTexture = new Texture("ball.png");
ball = new Sprite(ballTexture);
ball.setPosition(0,0);
circleShape = new CircleShape();
circleShape.setRadius(25f);
fixtureDef = new FixtureDef();
fixtureDef.shape = circleShape;
fixtureDef.density = 0.5f;
fixtureDef.friction = 0.4f;
fixtureDef.restitution = 0.6f;
circleBody = world.createBody(bodyDef);
circleBody.createFixture(fixtureDef);
box2DDebugRenderer = new Box2DDebugRenderer(
true, /* draw bodies */
false, /* don't draw joints */
true, /* draw aabbs */
true, /* draw inactive bodies */
false, /* don't draw velocities */
true /* draw contacts */);
Gdx.input.setInputProcessor(this);
}
@Override
public void show() {
System.out.println("show");
}
@Override
public void render(float delta) {
Gdx.gl.glClearColor(1, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.setProjectionMatrix(camera.combined);
batch.begin();
ball.draw(batch);
batch.end();
world.step(1 / 60f, 6, 2);
ball.setPosition(circleBody.getPosition().x - 25f, circleBody.getPosition().y - 25f);
box2DDebugRenderer.render(world, viewport.getCamera().combined);
}
@Override
public void resize(int width, int height) {
viewport.update(width, height);
System.out.println("resize");
}
@Override
public void pause() {
System.out.println("pause");
}
@Override
public void resume() {
System.out.println("resume");
}
@Override
public void hide() {
System.out.println("hide");
}
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
viewport.getCamera().unproject(point.set(screenX, screenY, 0));
return false;
}
}
108.000 km/h
. Would you zoom in on the earth it would disappear in nanoseconds but if you zoom out of the solar system you won't even see it move. TrycircleShape.setRadius(.11f);
and zoom in. Or increase the gravity, but that can cause issues later on. – Madmenyo