I'm just starting to learn LibGDX and have been having some troubles getting my world size to match with my texture size and box2d bodies. I have a texture 64x64 that I am trying to display but it takes up half of the window, both on desktop and android. I've tried scaling the texture down also. I am wondering if this has anything to do with my two variables FRUSTUM_WIDTH and FRUSTUM_HEIGHT being used in the creation of my camera.
int FRUSTUM_WIDTH = 8;
int FRUSTUM_HEIGHT = 15;
World world;
Box2DDebugRenderer debugRenderer;
@Override
public void create () {
batch = new SpriteBatch();
img = new Texture("player.png");
player = new Sprite(img);
player.setPosition(5, 5);
//player.scale(.8f);
camera = new OrthographicCamera(FRUSTUM_WIDTH, FRUSTUM_HEIGHT);
camera.position.set(FRUSTUM_WIDTH / 2, FRUSTUM_HEIGHT / 2, 0);
world = new World(new Vector2(0, -50), true);
debugRenderer = new Box2DDebugRenderer();
setUpBox2D();
}
private void setUpBox2D()
{
BodyDef bodyDef = new BodyDef();
bodyDef.type = BodyDef.BodyType.DynamicBody;
bodyDef.position.set(4, 10);
Body body = world.createBody(bodyDef);
CircleShape circle = new CircleShape();
circle.setRadius(1);
FixtureDef fixtureDef = new FixtureDef();
fixtureDef.shape = circle;
fixtureDef.density = 0.1f;
fixtureDef.friction = 0.1f;
fixtureDef.restitution = 0.5f;
Fixture fixture = body.createFixture(fixtureDef);
BodyDef groundBodyDef = new BodyDef();
groundBodyDef.position.set(new Vector2(0, 1));
Body groundBody = world.createBody(groundBodyDef);
PolygonShape groundBox = new PolygonShape();
groundBox.setAsBox(camera.viewportWidth, 1.0f);
groundBody.createFixture(groundBox, 0);
}
@Override
public void render () {
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
drawScene();
updateScene();
}
private void drawScene()
{
debugRenderer.render(world, camera.combined);
camera.update();
batch.setProjectionMatrix(camera.combined);
batch.begin();
player.draw(batch);
batch.end();
world.step(1/60f, 6, 2);
}
private void updateScene()
{
}
I do have a resize method but it is currently empty.
The window size is 480 by 800. I looked at a game called Super Jump on Github which helped fix my camera issue, but I am still having issues with the giant textures